AS3 Forlooping for buttons Help


i having trouble creating forloop structure lines of code

 

button1.addeventlistener(mouseevent.click ,mybtn1);

function mybtn1(evt:mouseevent):void

{

          var themc:mc1 = new mc1();

    addchild(mymc);

}

 

 

button2.addeventlistener(mouseevent.click ,mybtn2);

function mybtn2(evt:mouseevent):void

{

          var themc2:mc2 = new mc2();

             addchild(mymc2);

}

 

 

button3.addeventlistener(mouseevent.click ,mybtn3);

function mybtn3(evt:mouseevent):void

{

          var themc3:mc3 = new mc3();

             addchild(mymc3);

}

 

how forloop lines of code?

 

i have tried

 

for( var i:int=0; i<3: i++)

{

     button(i).addeventlistener(mouseevent.click,mybtn(i));

     function mybtn(i) (evt:moustevent):void

     {

          var themc(i):mc(i) = new mc(i);

          addchild(mymc(i));

}

 

but has errors

try friend,

 

for(var i:int=1;i<4;i++)

{

    ["button"+i].ivalue=i;

    ["button"+i].addeventlistener(mouseevent.click,onclickfunction);

}

 

function onclickfunction(event:mouseevent):void

{

    var mcclass:class=getdefinitionbyname("mc"+event.currenttarget.ivalue) class;

    addchild(new mcclass());

}

 

...cheers...



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support