I am building a grid of buttons dynamically in a for loop from XML. I am then assigning them button.label and button.name from the array. The grid appears, the buttons have the right label, the event.target.name method produces the name on the button in a trace. Now how do I attach that to a function dynamically? I need the name of the button to call the next step.
Code looks like this so far.
import flash.display.Sprite;
import fl.controls.Button;
import flash.events.MouseEvent;
var jwPremURL:URLRequest = new URLRequest(“jwPrem.xml”);
var xmlLoader:URLLoader = new URLLoader(jwPremURL);
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
var jwPremXML:XML = new XML();
jwPremXML.ignoreWhitespace = true;
var posY:Number = 50;
var wTypeSelected:String = new String();
var typeButtonName:String = new String();
function xmlLoaded(evt:Event):void{
jwPremXML = XML(xmlLoader.data);
//Set array for window type
var wType:Array = new Array(“SLIDER”,“SINGLE-HUNG”,“PICTURE”,“CASEMENT”,“AWNING”,“PATIO-DOOR”,“GEO-RADIUS”);
//Add type buttons
for(var i:int =0;i < wType.length; i++){
var typeButton:Button=new Button();
typeButton.scaleX=1.5;
typeButton.scaleY=1.5;
typeButton.x=20;
typeButton.y=posY;
typeButton.label = wType*;
typeButton.name = wType*;
addChild(typeButton);
typeButtonName=typeButton.name
posY = posY+40;
trace (typeButtonName);
}
}
this.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent):void
{
// TRACES THE NAME OF THE BUTTON CLICKED
trace(event.target.name, ‘clicked’);
}
Any help would be great.