4 Replies Latest reply on Dec 6, 2010 5:10 PM by kglad

    swapDepths causing problems with mc duplicates

    Dragonis00

      Hello Everyone,

       

      Is there any way to bring a duplicate mc with a variable depth to the front on RollOver, and then return to it's original depth on RollOut?

       

      I am currently using swapDepths(1000);

       

      I can't have the exact depths swapped because there could be any number of duplicates on screen at any given time, so that won't work.  I have searched high and low for an answer to this.

       

      The code I have works to a limit; when I mouse over the mc duplicate, it moves to the top just fine, but multiple other mc duplicates below it scramble depths (that is to say, they move up and down in depth at random).

       

      I want two thing to happen to only one mc at a time.

       

      1)  bring to front onRollOver and return to original position on RollOut

       

      2) bring to front onRelease, and stay there in front.

       

      Here is what I have so far.

       

       

      var num:Number;

      if(num == null){

      num = 0;

      }

      var buttonID:MovieClip;

       

      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();

      this.swapDepths(1000);

       

       

          };

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

              this.stopDrag();

       

       

          };

       

       

      buttonID.onRollOver = function () {

              this.swapDepths(1000);

       

          };

      };

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

          buttonID.stopDrag();

      };

       

       

       

      Can anyone help figure this out?

        • 1. Re: swapDepths causing problems with mc duplicates
          Dragonis00 Level 1

          I'm still having problems but they've just gotten a little easier.  I found this thread explaining how to get and save mc depth information for use later in a function.

           

          http://forums.adobe.com/message/408641#408641

           

          Now I can have a duplicate mc rise to a top level depth and then return to it's original depth.

           

          My problem now is that due to the onRollOut function returning my mc to it's original depth, I can't click to have the mc be brought to the top and stay like I want because it returns to the lower original depth onRollOut.  I want to be able to RollOverr an mc so you can see it and RollOut so it goes back, but if you want it to stay on top all you have to do is click.  But that isn't working.

           

          Here is my code now...

           

           

          var num:Number;

          if(num == null){

          num = 0;

          }

          var buttonID:MovieClip;

           

           

          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();

                  this.swapDepths(1000);

               };

           

           

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

                  this.stopDrag();

              };

           

           

           

               buttonID.onRollOver = function(){

                    this.savedDepth = this.getDepth();

                    this.swapDepths(1000);

               };

           

           

           

               buttonID.onRollOut = function(){

                    this.swapDepths(this.savedDepth);

               };

           

          };

           

           

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

              buttonID.stopDrag();

          };

           

           

           

           

          Is there any way to void RollOut on CLICK?

           

          All I can find are AS3 discussions on voiding RollOut on CLICK.

          • 2. Re: swapDepths causing problems with mc duplicates
            kglad Adobe Community Professional & MVP

            use a variable when your mc button is clicked:

             


             

             

            var num:Number;

            if(num == null){

            num = 0;

            }

            var buttonID:MovieClip;

             

             

            mcName.onPress = function() {

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

             

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

                buttonID.startDrag();

                buttonID.onPress = function() {

            this.clicked=true;

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

                    this.startDrag();

                    this.swapDepths(1000);

                 };

             

             

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

                    this.stopDrag();

                };

             

             

             

                 buttonID.onRollOver = function(){

                      this.savedDepth = this.getDepth();

                      this.swapDepths(1000);

                 };

             

             

             

                 buttonID.onRollOut = function(){

            if(!this.clicked){

                      this.swapDepths(this.savedDepth);

            } else {

            this.clicked=false;

            }

                 };

             

            };

             

             

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

                buttonID.stopDrag();

            };

             

             

             

             

             

             

            All I can find are AS3 discussions on voiding RollOut on CLICK.

            • 3. Re: swapDepths causing problems with mc duplicates
              Dragonis00 Level 1

              Thanks, but it didn't quite work  It seems to be having the backwards effect of what I need. I need the object to stay on top when clicked and remain on top when released so that when the mouse rolls out, it won't affect its depth anymore.  I think that an if else statement is exactly what I need though, you're right about that, I just can't find where to put it to make it work just right.

               

              Any other ideas?

              • 4. Re: swapDepths causing problems with mc duplicates
                kglad Adobe Community Professional & MVP

                copy and paste the code you used.