How do you pass variable values between functions where the addEventListener is in the first function? I am trying to get the color value passed into my event handler. This is driving me buggy.
// Create the xmlLoaded function
function xmlLoaded(event:Event):void {
myXML = XMLList(myLoader.data);
var a:int=1;
var b:int=1;
// Run the "for each" loop to iterate through all of the menu items listed in the external XML file
for each (var ListItem:XML in myXML..ListItem) {
var listColor:String = ListItem.itemColor.toString();
var listLabel:String = ListItem.itemLabel.toString();
//trace(xt);
var rect:MovieClip = new MovieClip();
var color:Number = Number("0x"+listColor);
rect.graphics.lineStyle(1, 0x000000);
rect.graphics.beginFill(color);
rect.graphics.drawRect(10,10,w,h);
rect.graphics.endFill();
rect.x = xt;
rect.y = yt;
// This all pertains to the text fields that give our boxes their labels, alter values to your liking
var myText1:TextField = new TextField();
myText1.text = listLabel;
myText1.autoSize = TextFieldAutoSize.LEFT;
//set location of text field.
myText1.x = xt+10;
myText1.y = yt+47;
//add cell
addChild(rect);
//add text of cell OVER the cell
addChild(myText1);
xt = xt+w+space;//set the spacing horizontal
b=b+1;//next column
//then changes must be done: prepare for next row
if (b>j) {
b=1;
yt = yt+h+space;//set the spacing vertically
xt = 0;
}
//add mouseEvents for squares
rect.addEventListener(MouseEvent.CLICK, getColorHandler);
rect.buttonMode = true;
}
}
function getColorHandler(event:MouseEvent):void {
trace(event.currentTarget.transform.colorTransform.color.toString(16));
var ct:ColorTransform = floorTile.transform.colorTransform;
ct.color = uint("0x" +event.currentTarget.transform.colorTransform.color.toString(16));
floorTile.transform.colorTransform = ct;
}