3 Replies Latest reply on May 9, 2006 11:09 AM by Sarford

    depth of movieclips gets screwed-up

    Sarford
      Ok I tried to resolve this before without any luck.
      Tim was a big help but I don't realy understand it yet.

      I have a flash movie, in that movie there are 15 instances ("drop1_mc" - "drop15_mc") of a movieclip all on the same level in the timeline.
      In frame 1 I give them a depth with getNextHighestDepth. I trace the depths and all works fine.

      In frame 2 I swap the stacking order with:

      drop15_mc.swapDepths(drop14_mc);
      drop14_mc.swapDepths(drop13_mc);
      drop13_mc.swapDepths(drop12_mc);
      .....
      drop2_mc.swapDepths(drop1_mc);

      Basicly putting the lowest movieclip on top.
      I trace the depths again and all works fine.

      At frame 30 I jump back to frame 2 (nothing happens inbetween).
      But now all depths have gone loco! What am I doing wrong??

      here is the code:

      FRAME 1:
      var k = 1;

      for (i=1; i<=15; i++) {
      this["drop"+i+"_mc"].gotoAndStop(12);
      }

      drop1_mc.swapDepths(_root.getNextHighestDepth());
      drop2_mc.swapDepths(_root.getNextHighestDepth());
      drop3_mc.swapDepths(_root.getNextHighestDepth());
      drop4_mc.swapDepths(_root.getNextHighestDepth());
      drop5_mc.swapDepths(_root.getNextHighestDepth());
      drop6_mc.swapDepths(_root.getNextHighestDepth());
      drop7_mc.swapDepths(_root.getNextHighestDepth());
      drop8_mc.swapDepths(_root.getNextHighestDepth());
      drop9_mc.swapDepths(_root.getNextHighestDepth());
      drop10_mc.swapDepths(_root.getNextHighestDepth());
      drop11_mc.swapDepths(_root.getNextHighestDepth());
      drop12_mc.swapDepths(_root.getNextHighestDepth());
      drop13_mc.swapDepths(_root.getNextHighestDepth());
      drop14_mc.swapDepths(_root.getNextHighestDepth());
      drop15_mc.swapDepths(_root.getNextHighestDepth());

      for (i=1; i<=15; i++) {
      trace("New Depth: "+this["drop"+i+"_mc"].getDepth());
      }

      FRAME 2:
      this["drop"+k+"_mc"]._visible = false;

      drop15_mc.swapDepths(drop14_mc);
      drop14_mc.swapDepths(drop13_mc);
      drop13_mc.swapDepths(drop12_mc);
      drop12_mc.swapDepths(drop11_mc);
      drop11_mc.swapDepths(drop10_mc);
      drop10_mc.swapDepths(drop9_mc);
      drop9_mc.swapDepths(drop8_mc);
      drop8_mc.swapDepths(drop7_mc);
      drop7_mc.swapDepths(drop6_mc);
      drop6_mc.swapDepths(drop5_mc);
      drop5_mc.swapDepths(drop4_mc);
      drop4_mc.swapDepths(drop3_mc);
      drop3_mc.swapDepths(drop2_mc);
      drop2_mc.swapDepths(drop1_mc);

      for (i=1; i<=15; i++) {
      trace("New Depth: "+this["drop"+i+"_mc"].getDepth());
      }

      this["drop"+k+"_mc"].gotoAndStop (1);
      this["drop"+k+"_mc"]._visible = true;
      this["drop"+k+"_mc"].gotoAndPlay (1);

      FRAME 30:
      var k=k+1;
      if (k>15) {
      var k= 1;
      }
      trace("Var K: "+k);
      gotoAndPlay(2);
        • 1. Re: depth of movieclips gets screwed-up
          Level 7
          Glad you could move forward. Ok, next step with some extra info (please
          read all, the solution is at the bottom ):

          1) Flash uses depths -16383 to -1 for elements that you place on stage
          at author-time (in Flash).
          2) Flash uses depths 0 and above for elements that are placed
          dynamically (using attachMovie, duplicateMovieClip, createEmptyMovieClip)
          3) When the playhead plays, Flash uses the depths as identifier to know
          when to move, draw, and remove movieclips.

          Implications of the above:
          ==========================
          * in a standard situation, you have a movieclip at a author-time depth,
          you can move the movieclip's position around, and have your playhead
          move forward and backward. Flash will realize that the movieclip still
          occupies the original depth and will let it be.

          * however _IF_ you swap a movieclip from the author-time depths to the
          dynamic depths _AND_ if you play your timeline forward _AND_ if you jump
          back to where Flash is supposed to draw the author-time movieclips, THEN
          the following will happen:
          - Flash will see that the depth at which the author-time movieclip
          must be is now empty and will assume it must place the movieclip again.
          - You will then have duplicate movieclips _with the same name_ on
          stage: one at a positive depth (the one you manipulated), and one at
          negative depth (the one Flash added again as per the author-time
          specification). Of course the result will be all screwed up.

          OK, this may sound a bit weird, here is a simple test case to illustrate
          this issue:
          1) create new flash movie
          2) in the library create a new movieclip with a simple shape maybe a
          circle or a rectangle
          3) place the movieclip on stage and name it "myMC";
          4) add some code to the timeline as follow:

          [frame 1]
          // nothing here

          [frame 2]
          // move the movieclip to a positive depth
          myMC.swapDepths(this.getNextHighestDepth());
          // shift it
          myMC._x += 10;
          myMC._y += 10;

          [frame3]
          stop();
          this.onMouseDown = function()
          {
          // when you will click the mouse,
          // the duplicate will appear
          this.gotoAndPlay(1);
          }



          Solutions to this problem:
          ==========================
          - do NOT change the depth of author-time movieclips, and especially, do
          not move them to positive depths (if your aplpication must be dynamic,
          use attachMovie to load the movieclips from the library directly to
          positive depths)
          - If you must move author-time movieclips to positive depths, do NOT
          jump backward in your timeline.


          hth,
          Tim.

          PS1: there are further implications to the 3 rules aboves but they are
          not affecting you right now so I wont elaborate on them to not confuse
          you

          PS2: when you face a problem, always try to build the simplest test case
          that shows the problem. That is the best way to find out whether the
          problem is due an error is in your code or to an unexpected behavior of
          the Flash player.



          Sarford wrote:
          > Ok I tried to resolve this before without any luck.
          > Tim was a big help but I don't realy understand it yet.
          >
          > I have a flash movie, in that movie there are 15 instances ("drop1_mc" -
          > "drop15_mc") of a movieclip all on the same level in the timeline.
          > In frame 1 I give them a depth with getNextHighestDepth. I trace the depths
          > and all works fine.
          >
          > In frame 2 I swap the stacking order with:
          >
          > drop15_mc.swapDepths(drop14_mc);
          > drop14_mc.swapDepths(drop13_mc);
          > drop13_mc.swapDepths(drop12_mc);
          > .....
          > drop2_mc.swapDepths(drop1_mc);
          >
          > Basicly putting the lowest movieclip on top.
          > I trace the depths again and all works fine.
          >
          > At frame 30 I jump back to frame 2 (nothing happens inbetween).
          > But now all depths have gone loco! What am I doing wrong??
          >
          > here is the code:
          >
          > FRAME 1:
          > var k = 1;
          >
          > for (i=1; i<=15; i++) {
          > this.gotoAndStop(12);
          > }
          >
          > drop1_mc.swapDepths(_root.getNextHighestDepth());
          > drop2_mc.swapDepths(_root.getNextHighestDepth());
          > drop3_mc.swapDepths(_root.getNextHighestDepth());
          > drop4_mc.swapDepths(_root.getNextHighestDepth());
          > drop5_mc.swapDepths(_root.getNextHighestDepth());
          > drop6_mc.swapDepths(_root.getNextHighestDepth());
          > drop7_mc.swapDepths(_root.getNextHighestDepth());
          > drop8_mc.swapDepths(_root.getNextHighestDepth());
          > drop9_mc.swapDepths(_root.getNextHighestDepth());
          > drop10_mc.swapDepths(_root.getNextHighestDepth());
          > drop11_mc.swapDepths(_root.getNextHighestDepth());
          > drop12_mc.swapDepths(_root.getNextHighestDepth());
          > drop13_mc.swapDepths(_root.getNextHighestDepth());
          > drop14_mc.swapDepths(_root.getNextHighestDepth());
          > drop15_mc.swapDepths(_root.getNextHighestDepth());
          >
          > for (i=1; i<=15; i++) {
          > trace("New Depth: "+this.getDepth());
          > }
          >
          > FRAME 2:
          > this._visible = false;
          >
          > drop15_mc.swapDepths(drop14_mc);
          > drop14_mc.swapDepths(drop13_mc);
          > drop13_mc.swapDepths(drop12_mc);
          > drop12_mc.swapDepths(drop11_mc);
          > drop11_mc.swapDepths(drop10_mc);
          > drop10_mc.swapDepths(drop9_mc);
          > drop9_mc.swapDepths(drop8_mc);
          > drop8_mc.swapDepths(drop7_mc);
          > drop7_mc.swapDepths(drop6_mc);
          > drop6_mc.swapDepths(drop5_mc);
          > drop5_mc.swapDepths(drop4_mc);
          > drop4_mc.swapDepths(drop3_mc);
          > drop3_mc.swapDepths(drop2_mc);
          > drop2_mc.swapDepths(drop1_mc);
          >
          > for (i=1; i<=15; i++) {
          > trace("New Depth: "+this.getDepth());
          > }
          >
          > this.gotoAndStop (1);
          > this._visible = true;
          > this.gotoAndPlay (1);
          >
          > FRAME 30:
          > var k=k+1;
          > if (k>15) {
          > var k= 1;
          > }
          > trace("Var K: "+k);
          > gotoAndPlay(2);
          >
          • 2. Re: depth of movieclips gets screwed-up
            Sarford Level 1
            Hi Tim,

            Thank you soooo much man, you are a realy big help!
            I never knew that flash sees a difference between dinamicly placed movieclips and author-time movieclips. I gues that was the whole problem.

            Now I'm gonna try your attachMovie routine and see if that works.
            I'll let you know if I succeed of need more of your help

            thanks again mate!
            • 3. Re: depth of movieclips gets screwed-up
              Sarford Level 1
              Hi Tim,

              I wanted to thank you once more. With your help I was able to solve the problem. All I did was delete the code in frame 1 witch gave the movieclips new depths. Thank you for your lenghtly explanation on the inner workings of the movieclip!

              Thanks pal!