Pass argument in EventHandler Callback?

Hello,

I was wondering if there was a way to pass an argument in the callback of an EventHandler?

on(name: string, callback, scope?) -> pc.EventHandler

For example:

Foobar.prototype.initialize = function(){
    this.buttonOne.element.on('mouseup',this.MouseUp(1),this);
    this.buttonTwo.element.on('mouseup',this.MouseUp(2),this);
};

Foobar.prototype.MouseUp = function(id){
    console.log("Clicked: " + id.toString());
};

Best to wrap it around another function callback

Foobar.prototype.initialize = function(){
    this.buttonOne.element.on('mouseup', function(event) { this.MouseUp(1); }.bind(this), this);
    this.buttonTwo.element.on('mouseup', function(event) { this.MouseUp(2); }.bind(this), this);
};

Foobar.prototype.MouseUp = function(id){
    console.log("Clicked: " + id.toString());
};
2 Likes

Awesome! Thanks for the help!