3 Replies Latest reply on Dec 2, 2010 3:10 PM by Ned Murphy

    Need help! DuplicateMovieClip AS2: duplicates disappear when new duplicates are loaded...why?

    Dragonis00

      Hello everyone,

       

      I apologize if this question has already been asked and answered, but I have yet to find it so I am posting this in the hopes of finding an answer.

       

      I am making a drag and drop game using AS2 in Flash CS5 where mc items are duplicated and enlarged from a menu and can be placed anywhere on the stage to create a custom robot.  Each part (arms, head, feet, etc.) is it's own mc with unique instance names.  I have the drag and drop part all figured out, and I even have the duplicateMovieClip part working...

       

      HOWEVER...

       

      Whenever I move from the current frame that an object was duplicated in, to another frame and then back, the clips dissapear one by one if you try to create a new one.  Each list of menu items are in their own frames (heads, torsos, arms, etc.).  As the duplicates are made, they remain on stage no matter what frame you go to and can still be dagged around, which is good, but as I said previously, they dissappear when you create a new duplicate.  Not all disappear at once,  only older created duplicates disappear as you bring in new duplicates.

       

      Why is this and how can it be fixxed?

       

      Judging by my tracers, it looks to me like the depth is resetting back to 0 as the new frame loads...I don't know how to circumvent this. Is there any way to add some sort of check that looks for existing duplicates before creating a new one?

       

      here is the code I am using for each of my parts (instance names are the only thing that changes)  (I changed the instance name to mcname for simplicity)

       

       

       

      ///////////////this part is added only once//////////////

       

       

      var num:Number = 0;

      var buttonID:MovieClip;

       

       

      /////////this is added for every object, but on the main timeline and not the object and is added to the frames the objects reside in//////////////////////

       

      mcname.onPress = function() {

          buttonID = mcname.duplicateMovieClip("mcname"+num, num++);

       

          trace(buttonID+" -- Was created");

          buttonID.startDrag();

          buttonID.onPress = function() {

              trace("Currently dragging --> "+this._name);

              this.startDrag();

          };

          buttonID.onRelease = buttonID.onReleaseOutside=function () {

              this.stopDrag();

       

       

          };

      };

      mcname.onRelease = mcname.onReleaseOutside=function () {

          buttonID.stopDrag();

      buttonID._xscale = 150;

      buttonID._yscale = 150;

      };