I’m working on a simple project where I load an XML file and make it into a four tier menu. I have a decent amount of programming experience but not much with AS3. I am stuck on one issue here:
// SETUP VARIABLES
// FIRST ROW
var firstSelection:String = "";
var firstRow:Array = new Array ("Home", "About", "Products", "Services", "Contact");
var firstX:int = 20;
// SPACING
var yStart:int = 20;
var yDifference:int = 20;
// LOOP THROUGH
for (var i:String in firstRow) {
var firstText:TextField = new TextField();
var firstTemp:int = int(i);
firstText.text = firstRow*;
addChild(firstText);
firstText.x = firstX;
firstText.y = yStart + (yDifference * firstTemp);
trace(firstText.y);
firstText.textColor = 0x000000;
firstText.addEventListener(MouseEvent.CLICK, function(evt:Event) {clickFirst(evt, firstText.text)}, true);
firstText.addEventListener(MouseEvent.CLICK, function(evt:Event) {clickFirst(evt, firstText.text)}, false);
}
function clickFirst(event:Event, secondText:String):void {
trace(secondText);
trace(this);
}
stop();
Basically when I trace “secondText” I want it to return the String of the textField that was clicked on. For example if you clicked on “Home” secondText would be set to “Home.” Unfortunately, because of my misunderstanding of eventListeners and loops secondText only returns “Contact” no matter which textField you click. This is because it’s the last item in the array.
I’m sure this has something to do with creating unique variables or eventListeners for each textField but alas my knowledge of AS3 can’t take me that far. Could anyone point me in the right direction? I would really appreciate it.
Also I’d like to point out that if I did know what the items in the navigation were going to be beforehand I would never create a menu like this. However, the purpose of this menu is to load the XML file and dynamically generate the navigation.
I hope I have been clear enough! Thanks.