Button clicking... how do i click it once?

i have a button script on a button

var Button = pc.createScript('button');

Button.attributes.add('shift', {type: 'number'});
var self;
var jumpBy;
// initialize code called once per entity
Button.prototype.initialize = function() {
    self = this;
    jumpBy = self.shift;

// update code called every frame
Button.prototype.update = function(dt) {
    self.entity.button.on('click', this.onRelease, this); 

Button.prototype.onRelease = function () {
    self.app.fire('game:Next', jumpBy);

When I click on it. the game:Next triggers every frame continuously rather than just once.
what have I done wrong?

if needed, you can give a look on the responder script

var ChangeMaterial2 = pc.createScript('changeMaterial2');
var _app;
var _myID;
var _Material;    

var URL_prefix ='https://s3-us-west-2.amazonaws.com/ticomsoft-image-repo/';
var URL_sufix = '.png';

// exposed fields
ChangeMaterial2.attributes.add("targetMaterial", {type: 'number'}); //targetMaterial
ChangeMaterial2.attributes.add("ID", {type: 'number'}); //ID

var imageUrl;
var material;

ChangeMaterial2.prototype.initialize = function() {
    var self = this;
    _Material = self.targetMaterial;
    _myID = self.ID;
    material = self.entity.model.meshInstances[_Material].material;    
    // listen for the player:move event
    //  self.app.on('game:Next', self.UpdateID(shift));
    var ImgFromURLwithCORS = function()
        // allow cross origin texture requests
        _app.loader.getHandler("texture").crossOrigin = "anonymous";

        var asset = new pc.Asset("myTexture", "texture", {
            url: imageUrl

        asset.on("load", function (asset) {
            material.diffuseMap = asset.resource;

    var UpdateID = function()
        imageUrl = URL_prefix+_myID+URL_sufix;
    var NextImage = function (jump)
    _app.on('game:Next',NextImage, this);

1 Like

Late response but your initalizing the button inside the update function which runs every frame. Therefore you are initializing the button every frame making it run continuosly.