11 Replies Latest reply on Aug 17, 2009 5:58 AM by Rootle

    SwapDepths within layers?

    Rootle

      I'm using a really simple bit of code on some fading in/out buttons which overlap each other slightly to ensure that the one with the cursor resting over it sits in front of the others:

       

      on (rollOver) {

      yellowspotmc.play("fadein");

      yellowspotmc.swapDepths(1000);

      }

       

      ..problem being that this brings the button in front of everything across all layers. How do I change my swapdepths to make sure the layers above the buttons STAY above? - or do I need to add something to the other layers to give them a fixed 'depth'? Cheers, R.

        • 1. Re: SwapDepths within layers?
          kglad Adobe Community Professional & MVP

          you'll find this easier if you take the time to understand how flash handles layers.

           

          layers do not exist in your swf.  each object in your swf is assigned a depth.  flash uses the layers to assign depths.  so objects in one layer (that's above another) are all assigned depths the are greater than all objects in the lower layer.

           

          if you want to reorder the objects that are in one layer in your fla, you could assemble all their depths (getDepth()) and use swapDepths with that group of depths.

          • 2. Re: SwapDepths within layers?
            Rootle Level 1

            Ok that all sounds sensible, but how/where do I use the 'getDepth()' command? (I only have a fairly basic understanding of flash).

            • 3. Re: SwapDepths within layers?
              kglad Adobe Community Professional & MVP

              if you wanted to order the objects on layerX and maintain their relative depth with respect to objects in layers above and below you could use something like:

               

              var layerXdepthA:Array=[obj1.getDepth(),obj2.getDepth(),...,objN.getDepth()];  // where obj1,...,objN are your layerX objects.

               

              you probably want to "order" layerXdepthA so you would use the sort() method of arrays:

               

              layerXdepthA.sort();

               

              so, if you wanted to change objZ's depth to the top of all layerX objects you would use:

               

              objZ.swapDepths(layerXdepthA[layerXdepthA.length-1]);

               

              if you wanted to change objZ's depth to the bottom of all layerX objects you would use:

               

              objZ.swapDepths(layerXdepthA[0]);

              • 4. Re: SwapDepths within layers?
                Rootle Level 1

                Ok, Im still not really that clear on how to apply your suggestion (I understand it all, but am still fumbling about with AS so not sure where to put it etc.)

                I have attached the file I am using, there are 5 circles that I need to apply this to, if you could sort one out for me so I can see how to do it then I can do the rest!

                Or perhaps it'd just be easier to explain to me when you see the problem!

                • 5. Re: SwapDepths within layers?
                  kglad Adobe Community Professional & MVP

                  what are the instance names of your 5 circles?

                  • 6. Re: SwapDepths within layers?
                    Rootle Level 1

                    They are the coloured circles named 'redspotmc, pinkspotmc, greenspotmc'..etc.

                    • 7. Re: SwapDepths within layers?
                      kglad Adobe Community Professional & MVP

                      what are the other two names?

                      • 8. Re: SwapDepths within layers?
                        Rootle Level 1

                        bluespotmc & yellowspotmc.

                        • 9. Re: SwapDepths within layers?
                          kglad Adobe Community Professional & MVP

                          var layerXdepthA:Array=[redspotmc.getDepth(),pingspotmc.getDepth(),greenspotmc.getDepth(),blu espotmc.getDepth(),yellowspotmc.getDepth()];

                           

                          layerXdepthA.sort();

                           

                          // call moveToTopXF() and pass a movieclip that you want to move to the top of the layerX movieclips

                           

                          function moveToTopXF(mc:MovieClip){
                          mc.swapDepths(layerXdepthA[layerXdepthA.length-1]);
                          }

                          // call movieToBottomXF() and pass the movieclip that you want to move to the bottom of the layerX movieclips

                          function moveToBottomXF(mc:MovieClip){
                          mc.swapDepths(layerXdepthA[0]);
                          }
                          1 person found this helpful
                          • 10. Re: SwapDepths within layers?
                            Gurflob Level 2

                            what i would do is just make everything on the higher layers swap depths with something higher than 1000

                             

                            so lets say your interactive stuff is on layer 1, its depth will go from 1 - 1000

                            then you make everything on layer 2 swap depths from 1001-2000

                             

                            for the movieclips on other layers just put:

                             

                            onClipEvent (load) {

                                 swapDepths(1001); //or whatever it needs to be

                            }

                            • 11. Re: SwapDepths within layers?
                              Rootle Level 1

                              Wicked that seems to have worked out well!

                               

                              I've uploaded what I have so-far here: http://www.samhumphrey.co.uk/new/DWcloud.html.

                               

                              It's obviously not finished by any means, but before I start tarting it up a bit, I want to make the rollOver/rollOuts a little less buggy - sometimes the cursour moves too fast for them to notice it's 'rolled out' etc. Any ideas?