|
-
loading MCs dynamically
Hi
I have a set of movieClips in libray which I want to load to the stage dynamically, think of it as a picture gallery except instead of loading jpg or any other image type I want to load movieClips, I was wondering if it is possible to create an array of mcs and load them dynamically to the stage?
Many Thanks!!
-
Senior Member
what you will need to do is setup a linkage for each clip you wish to attach from the library.
to do this, rightclick on the clips in the library and selected linakge, then check the "Export for actionscript" check box, and type your linkage name into the Identifier box.
now this linkage is the reference to the clip in the library.
you can now set up an array with all the linkages of your clips in, and attach them to the stage:
Code:
// set up the array with linkages.
var linkages:Array = ["clip1", "someotherLinkage", "clip2"];
for(var z = 0; z<linkages.length; z++){
// loop though the array and attach each clip from the library.
_root.attachMovie(linkage[z], "clip"+z, z);
}
look at flashs help files for more info on attachMovie();
HTH,
zlatan
-
Flashmatics
suppose the movieclips you wanna load have linkage names mc1,mc2,mc3 ...mc10 ... u wont really need an array because u can load them like:
Code:
var SW:Number = Stage.Width;
var SH:Number = Stage.Height;
var movie:MovieClip;
for(var i:Number=1; i<=10; i++){
movie = _root.attachMovie("mc"+i, "mc"+i, _root.getNextHighestDepth());
movie._x = Math.random() * SW;
movie._y = Math.random() * SH;
}
if u do wanna load them using an array heres the way to do it(suppose they have random linkage names)
Code:
var SW:Number = Stage.Width;
var SH:Number = Stage.Height;
var aMovies:Array = new Array("mcMan", "mcWoman", "mcDuck");
for(var i:Number=0; i < aMovies.length; i++){
movie = _root.attachMovie(aMovies[i], "mc"+i, _root.getNextHighestDepth());
movie._x = Math.random() * SW;
movie._y = Math.random() * SH;
}
-
Flashmatics
oops dudeqwerty beat me to it lol
-
Thanks to both of you dudeqwerty and silentweed. It's great to get a reply in such a short time!!
FlashSmashed
-
Senior Member
no worries,
take note of the positioning of "movie" in silentweed's code, if you dont put a postion the clip will just get attached to the topleft of the movie, like it would in my example. you can also have the positioning as an optional parameter in the attachMovie method. like so:
Code:
_root.attachMovie("myClip", "myClip", 0, {_x:100, _y:100});
HTH,
zlatan
-
Thanks dudeqwerty!!
you are a star
-
Senior Member
-
Flashmatics
what about me? am i a star too?
-
sorry silentweed if I forgot about you. you are a shiny bright star too!!
and I need you (in my dark and cloudy flash sky),
-
Flashmatics
hahaha ..anyway think ill hit the sack now..take care
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|