Skip to content

Instantly share code, notes, and snippets.

@FrancescoMaisto
Last active December 12, 2015 05:29
Show Gist options
  • Save FrancescoMaisto/4722381 to your computer and use it in GitHub Desktop.
Save FrancescoMaisto/4722381 to your computer and use it in GitHub Desktop.
Extends the standard Starling Button by adding an id parameter. The id parameter can then be retrieved from the event dispatched to the 'onButtonTriggered' listener. (see usage example in the first comment)
package ui
{
import starling.display.Button;
import starling.textures.Texture;
/**
* Extends the standard Starling Button by adding an id parameter
*
* @author Francesco Maisto (www.francescomaisto.com)
*/
public class IdButton extends Button
{
private var _id:uint;
public function IdButton(upState:Texture, text:String="", downState:Texture=null)
{
super(upState, text, downState);
}
public function get id():uint { return _id ; }
public function set id(value:uint):void { _id = value; }
}
}
@FrancescoMaisto
Copy link
Author

Extends the standard Starling Button by adding an id parameter. The id parameter can then be retrieved from the event dispatched to the 'onButtonTriggered' listener. For example:

private function onButtonTriggered(event:Event):void 
{ 
        var button:IdButton = event.target as IdButton; 
        var buttonName:String = button.name; 
        var id:uint = button.id;

        // Perform different actions based on buttonName and id
        if (buttonName == "backButton") 
                showScreen(id); 
        else if (buttonName == "clickedLevel")  
                startLevel(id); 
} 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment