开发者

AS3 using array to add EventListener to existing Button

开发者 https://www.devze.com 2023-01-08 11:45 出处:网络
I\'m trying to use an array to add a click listener to an existing Button. Black,Blue...etc are the button Names.

I'm trying to use an array to add a click listener to an existing Button. Black,Blue...etc are the button Names. the location of the nested button would be: this.mc1.mc2.contents.m3.black.addEventListener(MouseEvent.CLICK, doThisFunction);

 var myArray:Array = new Array ("black","blue","green","orange");
 for(var k:int =1; k<myArray.length; k++){ 
   var kmc:MovieClip = (myArray[k] as MovieClip);
         this.mc1.mc2.contents.m3.kmc.addEventListener(MouseEvent.CLICK, do开发者_StackOverflow社区ThisFunction);
    }

Any help would be greatly appreciated!


First kmc is a String:

var kmc:String = myArray[k];

Then the last line should be:

this.mc1.mc2.contents.m3[kmc].addEventListener(MouseEvent.CLICK, doThisFunction);
0

精彩评论

暂无评论...
验证码 换一张
取 消