0

I've dynamically created a menu using MovieClips as menu items inside a public function, but I also need to access these MovieClips on the timeline, however using similar code as below works for initially creating them, but not accessing them on the timeline.

I'm attempting to access functions and child MovieClips inside each menu items.

public function createMenuFunction():void {
    var buttonMC:menuButtonMC;
        for (var i:uint = 1; i <= totalTopicsI; i++) {
            buttonMC = new menuButtonMC();
            menuMC.contentMC.addChild(buttonMC);
            buttonMC.name = 'button' + i + 'MC';
            menuMC.contentMC.getChildByName('button' + i + 'MC').UI();
            menuMC.contentMC.getChildByName('button' + i + 'MC').y = (i - 1) * 70;
            menuMC.contentMC.getChildByName('button' + i + 'MC').updateTextFunction(textO['Topic ' + i]);
            menuMC.contentMC.getChildByName('button' + i + 'MC').addEventListener(MouseEvent.CLICK, updateCurrentTopicFunction);
            trace('Menu ' + i + ': ' + textO['Topic ' + i]);
        }
    }
}

For example, the following line of code works inside this function, but not on the timeline:

menuMC.contentMC.getChildByName('button' + i + 'MC').UI();

Any suggestions are welcome.

4

1 回答 1

0

尝试这个:

public var menuData:Array = new Array();
for (var i:uint = 1; i <= totalTopicsI; i++) {
  menuData[i] = new menuButtonMC();
  menuMC.contentMC.addChild(menuData[i]);
  menuData[i].name00 = 'button' + i + 'MC';
  menuMC.contentMC.getChildByName('button' + i + 'MC').UI(); 
  menuMC.contentMC.getChildByName('button' + i + 'MC').y = (i - 1) * 70; 
  menuMC.contentMC.getChildByName('button' + i + 'MC').updateTextFunction(textO['Topic ' + i]); 
  menuMC.contentMC.getChildByName('button' + i + 'MC').addEventListener(MouseEvent.CLICK, updateCurrentTopicFunction); 
  trace('Menu ' + i + ': ' + textO['Topic ' + i]); 
}

这样,您将保存所有按钮和属性。(name00不使用name

于 2012-08-06T03:31:29.433 回答