Skip to main content
Participant
June 4, 2008
Answered

Attaching Movie Clips at runtime from library

  • June 4, 2008
  • 3 replies
  • 654 views
Dear All,

I have 6 different clips in Library with the Linkage class given to following names: Class: mc0, mc1, mc2, mc3, mc4, mc5, mc6,


And I want to attach these clips dynamically at run time using the for loop in AS3.0:


For( var i=0; i<6; i++)
{

What should be the code for this at runtime attachment?

//

}


Regards,
Sridhar B
This topic has been closed for replies.
Correct answer srib
Thank you,

Its working fine and has been answered.

3 replies

June 5, 2008
Hi from Istanbul,

try my code. Maybe it helps:

for (var i:uint=0;i<7;i++)
{
var FromLibrary:Class=getDefinitionByName("mc"+i) as Class;
var mcx:MovieClip=new FromLibrary();
addChild(mcx);
mcx.x=20*i*i;
mcx.y=20*i*i;
}
sribAuthorCorrect answer
Participant
June 7, 2008
Thank you,

Its working fine and has been answered.
Ned Murphy
Legend
June 5, 2008
Dynamically naming variables isn't doable based on anything I've seen. You may want to rethink this and possibly see about bringing arrays into the picture. You could create new objects and dynamaically give them instance names.
Participating Frequently
June 4, 2008
I looked to see if I could find a way to do this, and convinced myself it's not possible. If it's important to do this in a loop (I can't imagine why, but maybe you have a reason) you may wish to add them explicitly with addChild(mc1) etc but locating them "off stage" then you can reference them with this["mc"+i] in a loop to change their coordinates to put them on stage.