A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: adding a movieclip to the stage

Hybrid View

  1. #1
    Senior Member
    Join Date
    Sep 2005
    Posts
    128

    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!

  2. #2
    Member
    Join Date
    Mar 2005
    Posts
    47
    try this...

    addChild(baddie[1]); // or whichever baddie you want to add to the stage [0], [1], etc.

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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.

  4. #4
    Senior Member
    Join Date
    Sep 2005
    Posts
    128

    how?

    how do I put the class into the array directly? That sounds exactly like what I need to do.

  5. #5
    Senior Member
    Join Date
    Sep 2005
    Posts
    128
    Wait I think I got it.

    baddieArray.push(new Baddie())

    is that right?

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center