I have some menu code which creates a number of submenu items and I want to be able to load SWF content into a container MC on the stage onClick. These are the relevant sections of code:
function onSelectItem(event:MouseEvent):void {
switch (instanceName) {
case instance1 :
startLoad("roots.swf");
break;
case instance2 :
startLoad("arrival.swf");
break;
case instance3 :
startLoad("post-war.swf");
break;
case instance4 :
startLoad("doubts.swf");
break;
default :
startLoad("roots.swf");
}
}
//CODE FROM A DIFFERENT FUNCTION
id = int(event.target.name);
submenus = menuArray[id].length;
var menuSubHolder:Sprite = new Sprite();
menuSubHolder.name = "sub" + String(id);
menuSubHolder.y = event.target.y + 18;
for (var j:int = 0; j < submenus; j++) {
menuSubText = new TextField();
menuSubText.x = event.target.x + 18;
menuSubText.y = j * 18;
menuSubText.text = menuArray[id][j];
menuSubText.autoSize = TextFieldAutoSize.LEFT;
menuSubHolder.addChild(menuSubText);
// DISPLAY CONTENT ON CLICK
menuSubText.addEventListener(MouseEvent.CLICK, onSelectItem);
}
The problem I’m finding is that AS 3 assigns some unpredictable instance numbers to the submenu items. How can I assign my own instance names to each of the submenu textfields on creation?