-
adding a movieclip to the stage
normally when i want to add a movieclip to the stage I would do this:
Code:
var baddie = new Baddie ();
addChild(baddie);
but I have an array of linkage ID's that I select from randomly at runtime so how do I code it to place it on stage? ex:
Code:
//I know this wrong I just wanted to give u an idea of what i'm trying to do
var baddie = new baddieArray[2]
addChild(baddie);
Please help!
-
try this...
addChild(baddie[1]); // or whichever baddie you want to add to the stage [0], [1], etc.
-
What is actually in your baddieArray? If it's Strings, then you can use getDefinitionByName to get the class, then create a new instance of that. But you should consider putting the class in the array directly.
-
how?
how do I put the class into the array directly? That sounds exactly like what I need to do.
-
Wait I think I got it.
baddieArray.push(new Baddie())
is that right?
-
No, that puts an instance of Baddie in the array. You want instances on the stage. You probably want to keep those in an array as well, but that's a separate subject.
You could put the class in the array like this:
Code:
baddieArray.push(Baddie);
Then you can create and put instances on the stage much like you originally tried.
Code:
var baddie:Baddie = new baddieArray[0]();
addChild(baddie);
This assumes that all your baddie classes extend Baddie. If they don't then type the baddie var as something else.
Code:
var baddie:DisplayObject = new BaddieArray[0]();
addChild(baddie);
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
|