4 Replies Latest reply on Apr 11, 2011 3:09 PM by Ned Murphy

    Layer always on top




      I am _very_ new to flash, and im making a simple flash sidescroller game to get things running, and I've run into a problem.


      So lets get straight to the point:

      I have a layer that i want to always be the top layer, because it is a "foggy" effect on the foreground.

      But the problem is, that my enemy-characters spawn on top of it, and it looks odd when my main character is under the fog but the enemies  (or ammunition) arent.


      So is there any way to force a layer to be always on the top?


      P.S. my enemies spawn by "_root.attachMovie ( "Enemy", "Enemy" + _root.getNextHighestDepth(), _root.getNextHighestDepth() );" if that has anything to do with it.

        • 1. Re: Layer always on top
          Ned Murphy Adobe Community Professional & MVP

          One approach could be to load your enemies into a movieclip that sits on a layer below your fog layer.


          Another possibility would be to use swapDepths each time you add a new enemy to have your fog movieclip switch depths with the newly added enemy.

          • 2. Re: Layer always on top
            Rothrock Level 5

            Yup. What Ned said. One big strength of flash is that you can use movieclips to organize your contents. This makes it easier to manage them. Generally you should only have a few basic, stable, non-changing, number of movieclips on your _root/main-timeline and then all the dynamic content is popped in and out of those as need be.


            Here is a great article to help you understand how depths work in Flash AS2.




            Of course if you are just starting with Flash, but hope to have a future with it, I would suggest not learning AS2 at all and moving right into AS3--which has a completely different way of handling depths.


            The other piece of advice (unasked for, but hey "you get what you pay for.") is that you should stop using _root and also stop using _getNextHighestDepth().


            _root will give you problems if/when the time comes that you want to load external swfs into other swfs. Ang _getNextHighestDepth will start getting twitchy if/when you have some Flash component in your library--even if it is never used on the stage!

            • 3. Re: Layer always on top
              Zavake Level 1

              Thank you both very much!


              I will try and switch into AS3, if i can.

              • 4. Re: Layer always on top
                Ned Murphy Adobe Community Professional & MVP

                You're welcome