A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Dynamically replacing library elements

  1. #1
    Senior Member
    Join Date
    Aug 2005
    Posts
    238

    Dynamically replacing library elements

    Hello All,

    I was curious if there was a way to dynamically replace library elements in flash. For instance say i make an animation of a girl jumping and it uses the library elements head, body, arms and legs. Is there a way to dynamically load in library elements head, body, arms and legs (say a boys) that replace the existing ones, so that the next time you call the animation you now see the same jumping animation but with the boys body elements In another project I accomplished this kind of idea by having for instance the head movieclip have many frames, one for each person; but this quickly becomes a nightmare as the animation becomes complicated (you have to keep doing like myhead.gotoAndStop(currentperson) on every single Keyframe of the head object); and this was also bad because all the graphical elements had to be in memory simultaneously.

  2. #2
    Senior Member
    Join Date
    Aug 2005
    Posts
    238
    Any ideas?

  3. #3
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Sure you can load any items from the library dynamically, although I don't think I understand your question or example fully enough to know what exactly your going for?

    Maybe try posting some of your code you have currently.

  4. #4
    Senior Member
    Join Date
    Aug 2005
    Posts
    238
    It should be simple to make a template; i just can't get it to work. For instance. Make a red box and make it a movie clip called Box (so now the movieclip Box is visible in the the Fla's library). Now make a movieclip called BoxScene and in it have the Box clip and have an animation (box slides from right to left or some such). Now what I want is for, when the swf is run, dynamically load another box from an external swf (say a green box), the is called Box and thus replaces the red box; so that when you watch the swf you now see a green box slide from right to left. I've been trying and have been unsuccessful. I find it a lot easier to just look at something that works and figure out how its working. Can you make a sample like this? Thanks.

  5. #5
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    So correct me if im wrong, you just want a box to show up when the swf loads and be a random color each load?

  6. #6
    Senior Member
    Join Date
    Mar 2001
    Location
    Location : Location
    Posts
    131
    Your example should work ok if, inside BoxScene you load the red_box or green_box .swf on the fly ....

    In relation to your first example, each limb_mc should merely be a 'holder' which then loads the required clip at runtime ....

    [edit] ->

    I'm trying to think ..... there were loads of hoops I had to jump through in order to dynamically load fonts at runtime (AS2) - but as I remember, if you put all the required clips into one swf, and then load that, once it IS loaded, all the clips become available as library items to be called during the remainder of the movie ...
    Last edited by TechNoiZ; 03-26-2008 at 08:43 PM.
    this[MCr.i + 'm_not_ok']._lyric = "you sing the words but you don't know what they mean";

  7. #7
    Senior Member
    Join Date
    Aug 2005
    Posts
    238
    The thing that makes this tricky is; I have to have the animation set already BEFORE run time, but not the object that is animating itself (think like a fighting game where everyone does the same moves).

  8. #8
    Senior Member
    Join Date
    Aug 2005
    Posts
    238
    Can anyone help me? It's driving me batty. Thanks.

  9. #9
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    I think if you could post yours files somewhere so we can look at them it may be easier to offer help. There is just too many variables to look at to say "this is your issue".

  10. #10
    Senior Member
    Join Date
    Aug 2005
    Posts
    238
    I am not in the middle of a project or anything. It is a theoretical question. If you have an element in your library called "boy", of which instances are created during the running of your movie; can you somehow load in another movie clip dynamically and make that the "boy" clip instead.

  11. #11
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    You can't replace items in your library via script, but you can load movieclips dynamically from the library.

  12. #12
    Senior Member
    Join Date
    Aug 2005
    Posts
    238
    Hmm....i'm not sure there is a way to do this then... I mean I can click the mouse and change like a bouncing ball into a bouncing hat or something, but it only works if the animation currently exists on the stage....

  13. #13
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    I think you are just confusing yourself, and your confusing me.

    Can you post your FLA with an example of what your trying to do?

    You can create a movieclip then load anything from the library into that clip, with a few exceptions.

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