-
Getting movieclips from the library dynamically
Hi I'm in the midst of a painstaking port from AS2 to AS3 on a game I have created. Now a piece of code I use a lot is for example;
function wave() {
for(var i:int = 0; i<10; i++) {
enemies.attachMovie("enemy"+i, i);
}
}
that way I can get enemy1, enemy2, enemy3,... and so on from my library.
how do I go about doing he same thing in AS3?
I have tried
var nextEnemy:MovieClip = new [enemy+i] as MovieClip;
and so on, but none of it works, any tips?
-
I'm no expert but you could try this...
Code:
function wave() {
for(var i:int = 0; i<10; i++) {
//enemies.attachMovie("enemy"+i, i);
var enemies:MovieClip = new MovieClip();
enimies.name = "enemy" + i;
}
}
I just did something like that last week & I'm pretty sure that was the code. Just make sure you export your clip from the library for actionscript.
-
Thanks for the reply, but in that code you just create an empty movieClip and name it enemy1, enemy2 and so on. You don't pick up anything from the library?
-
anyone? help would be greatly appreciated
and oh yeah right now, another thing has got me stuck.
I'm trying to reach a sprite that is added as an child a couple of sprites down the line, at firs I created Sprite1, and added it as a child on "_root" (I know as3 programmers hate that word then I added sprite2 to sprite1 and so on. How do I reach that sprite3?
var tweenThis:Sprite = Sprite(Sprite1.Sprite2.Sprite3);
is my first idea, but it didnt work, still some as2 left in me.
thanks
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
|