3 Replies Latest reply on Jul 16, 2010 8:06 AM by Oli_Wales

    Change order of Depths

    Oli_Wales Level 1

      Hi I have some movieclips stacked on top of each other, i've got them swapping depths onRelease, but I want them to swap in opposite direction to what they are now. Check out the link below, basically you click the 2nd or 3rd clip to call infront of the 1st, but i want to click the 1st to send to back and so on.

       

      http://www.baycreative.co.uk/Photos.swf

       

      Code as follows. Does anyone know what i would change to reverse the order?

       

       

      var mcs:Array = new Array (first_mc, second_mc, third_mc);

       

      var mc:MovieClip;
      var total:Number = mcs.length;

       

      for (var i:Number = 0; i < total; i++)
      {
          var mc:MovieClip = mcs[i];
          mc.onRelease = function ()
          {
              this.gotoAndPlay (2);
              this.onEnterFrame = function ()
              {
                  if (this._currentframe == 7)
                  {
                      this.swapDepths (getNextHighestDepth ());

       

                  }
              };
          };
      }

        • 2. Re: Change order of Depths
          rHemanth Level 2

          var mcs:Array = new Array(mc1, mc2, mc3);

           

          var mc:MovieClip;

          var total:Number = mcs.length;

           

          for (var i:Number = 0; i < total; i++)

          {

          var mc:MovieClip = mcs[i];

           

          mc.onRelease = function()

          {

          for (var j:Number = 0; j < total; j++)

          {

          if (this == mcs[j])

          {

          swapdepth(j);

          }

          }

          };

          }

           

           

          function swapdepth(k:Number)

          {

          trace(k);

          var num:Number = k - 1;

          for (var m = 0; m < total - 1; m++)

          {

           

          trace(num);

           

          var num2:Number = num;

          if (num2 < 0)

          {

          num2 = total + num2;

          }

          trace("K : " + k + " num: " + num2);

          mcs[k].swapDepths(mcs[num2]);

          num -= 1;

          }

          }

           

           

          This code just brings the a movieclip   with second highest depth  to foreground on clicking anywhere  on the movieclips.The movement of movieclips to foreground is cyclic.I hope this will be helpful

          • 3. Re: Change order of Depths
            Oli_Wales Level 1

            I know what you mean, but no this is not what i'm after, this just brings the back to the front.

             

            Where the code at the moment calls the images to the front, i also want to send the images to the back if needed, for example when the image in the top layer is clicked i would like this to go to the back, at the moment it does nothing (apart from it's own animation) but it doesnt change depth with the others.