A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Adding a movieclip instance to stage at runtime?

  1. #1
    Superstar!
    Join Date
    Jan 2003
    Location
    Toronto Canada
    Posts
    39

    Adding a movieclip instance to stage at runtime?

    I want to add an instance of a movieclip in my library to the stage, with Actionscript. But it seems the only methods i can find (attatchmovie ect...) , only add a movieclip into another movieclip.

    Isn't there a way to create an instance of a library object directly onto the _root level?

  2. #2
    incredibulus-actionscriptum magnetos's Avatar
    Join Date
    May 2001
    Posts
    2,160
    i think a simple _root.attachMovieClip("libraryname","newname",dept h)
    should work

  3. #3
    Superstar!
    Join Date
    Jan 2003
    Location
    Toronto Canada
    Posts
    39
    That was my first attempt.
    It didn't seem to work...
    If you can get it to work on yours, please let me know the details.

    And if anyone else has the answer, Im REALLY anxtious to find out.
    Last edited by Wakorobro; 01-30-2003 at 11:42 PM.

  4. #4
    Junior Member
    Join Date
    Sep 2001
    Location
    Decatur, IN USA
    Posts
    21
    attachMovie is the correct command to use. Make sure that you have the linkage setup in your library and that you don't give it the same depth as anything else, otherwise it won't work.

    Microsoft .NET MVP

  5. #5
    Superstar!
    Join Date
    Jan 2003
    Location
    Toronto Canada
    Posts
    39
    Ok,

    1 : how should i set up the linkage? Just export for actionscript and give it a name? And load on frame 1...

    2 : After that, the correct syntax would be
    _root.attatchmovie(LibObj,NewName,DisplayLevel) ?

    ( i ask these because its still not working )

    3 : is there a simple way to dynamically get the value of the next available depth?

    Thanks for the advice so far!
    Last edited by Wakorobro; 01-31-2003 at 12:35 AM.

  6. #6
    Senior Member artyom_ch's Avatar
    Join Date
    Jan 2003
    Location
    Russia, Murmansk
    Posts
    128
    Just store some variable for the current depth and when attaching new movie increment it.
    Wollt ihr das Bett in Flammen sehen?!

  7. #7
    Superstar!
    Join Date
    Jan 2003
    Location
    Toronto Canada
    Posts
    39
    AAH! Nevermind i just figured what was wrong.

    Stupid "expression" box in a command wasnt checked. GRR.

    But now i have yet another problem. When the new instance is added, any other instance of that same Library MovieClip disappears

  8. #8
    Junior Member
    Join Date
    Sep 2001
    Location
    Decatur, IN USA
    Posts
    21
    only reason that ever happens is because you gave it the same depth or the same name as one of the other items...check to make sure you didn't do that.

    Microsoft .NET MVP

  9. #9
    Superstar!
    Join Date
    Jan 2003
    Location
    Toronto Canada
    Posts
    39
    Good god! i fixed it!

    turns out i needed to add quotation marks around the LibraryObject name and the NewInstance name! Jeez, they should have automated that in Simple code mode! There's not even a "expression" checkbox to suggest the engine might assume its a variable!

    Anyway, it was a lot of typing, but problem solved!

    Thanks again, this place rocks!
    Last edited by Wakorobro; 01-31-2003 at 01:30 AM.

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