5 Replies Latest reply on Jul 19, 2006 4:14 AM by Newsgroup_User

    Swapping depths

    animee
      Hi all,

      i've got the following problem:

      I want to populate my stage with 20 squares.
      Each square's position (_x, _y), _rotation and depth is generated randomly by using the attachMovie() method.

      My code for a two square looks like this:

      this.attachMovie("green", "m1", random(500), {_x:100+random(600), _y:50+random(400), _rotation:random(360)});
      this.attachMovie("blue", "m2", random(500), {_x:100+random(600), _y:50+random(400), _rotation:random(360)});

      That works all fine.


      Now each square is dragabble and should change its depth to the highest when the user starts dragging.
      I think the - swapDepths - method should work but I have no idea how to determine the moviclip the current clip (which is dragged) does overlap.

      Any suggestions?
        • 1. Re: Swapping depths
          blemmo Level 1
          Why don't you let it swap with depth 501? Or probably with getNextHighestDepth() ? Then it should be above all others.
          • 2. Re: Swapping depths
            animee Level 1
            The problem is that although the depth is randomly genereted between 0-500, i get a value of -16383 when i trace the depth of the current clip with getDepth().

            And this value is the same for all the squares, it's always -16383

            • 3. Re: Swapping depths
              animee Level 1
              Alright - I've got it - Thanks for the tip with 501.

              I've done it with this:


              the code inside the squares:

              go.onPress = function() {
              this._parent.swapDepths(_root.topDepth);
              ++_root.topDepth;
              this._parent.startDrag();
              };

              the starting value of topDepth is 501.
              Now all works fine.

              Thank you very much. =)
              • 4. Re: Swapping depths
                blemmo Level 1
                You're welcome. FYI, the negative depth is typical for an MC that was put on stage in the Flash IDE. MCs with negative numbers can't be removed by removeMovieClip(), which is quite annoying... The MC you traced should be such an MC.

                cheers,
                blemmo
                • 5. Re: Swapping depths
                  Level 7
                  You realise you are going to run into problems here? Attaching clips at
                  random depths, will eventually lead to 2 clips attaching at the same depth,
                  so one will be deleted...

                  --
                  -------------------------------
                  Remove '_spamkiller_' to mail
                  -------------------------------