Skip to content

Instantly share code, notes, and snippets.

@goshki
Created May 10, 2011 19:19
Show Gist options
  • Save goshki/965179 to your computer and use it in GitHub Desktop.
Save goshki/965179 to your computer and use it in GitHub Desktop.
Flixel state for testing instantiation of multiple buttons at once
package {
import org.flixel.FlxButton;
import org.flixel.FlxG;
import org.flixel.FlxState;
/**
* An example Flixel state that instantiates multiple buttons at once during creation. To achieve
* this, it uses an array of dynamic configuration objects that hold properties specific for each
* button.
*/
public class MultipleButtonInstantiationTestState extends FlxState {
public static var buttons:Array = [
{
x: 2,
y: 2,
label: "First button",
onClick: onFirstButtonClick
},
{
x: 2,
y: 22,
label: "Second button",
onClick: onSecondButtonClick
},
{
x: 2,
y: 42,
label: "Third button",
onClick: onThirdButtonClick
}
];
public static function onFirstButtonClick():void {
FlxG.log( "First button clicked." );
}
public static function onSecondButtonClick():void {
FlxG.log( "Second button clicked." );
}
public static function onThirdButtonClick():void {
FlxG.log( "Third button clicked." );
}
override public function create():void {
for each ( var button:Object in buttons ) {
add( new FlxButton( button.x, button.y, button.label, button.onClick ) );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment