1 Reply Latest reply on Oct 19, 2010 10:54 AM by kglad

    Drawing on different layers

    woodtd

      Hi all,

        I have a flash CS3 AS 2.0 that is composed of 7 layers.  I am trying to draw on a specific layer but I can't figure out how.

       

      One layer is named Carm and this is where my button controls are;

       

      //Layer Carm btn controls

       

      btnOn.onPress = funtion(){

      lineStyle(1, 0XFF0000, 100);

      moveTo (340, 200);

      lineTo (340, 400);

       

      btnOn.onRelease = function(){

      lineStyle(4, 0x000000, 50);

      lineTo(60,15);

      }

       

       

      This works to draw a line but it looks like it is on a layer behind all of the others.

       

      How can I draw on differnet layers I guess is the question I have?

       

      Thanks for any assistance,

      Tim W

        • 1. Re: Drawing on different layers
          kglad Adobe Community Professional & MVP

          you can only use the draw api applied to movieclips.  the code you showed uses the default (current) timeline.

           

          in addition, layers don't exist in your published swf.  however, all on-stage objects in your swf are assigned a depth by flash.  flash uses your layers to assign higher depths to obects on upper-most layers.

           

          you can use actionscript to control the depth of movieclips.  so, putting that all together, you need to apply your drawing code to a movieclip and then assign its depth so it fits where you want:

           

          var mc:MovieClip=this.createEmptyMovieClip("mc',this.getNextHighestDepth());

          btnOn.onPress = funtion(){

          with(mc){

          lineStyle(1, 0XFF0000, 100);

          moveTo (340, 200);

          lineTo (340, 400);

          }

          }

           

          btnOn.onRelease = function(){

          with(mc){

          lineStyle(4, 0x000000, 50);

          lineTo(60,15);

          }

          }

           

          // then find the depth you want use for mc.  this is easiest done by adding a temporary movieclip to your stage in the layer/depth you want to use for mc, assign it an instance name (eg, tempMC) and use:

           

          trace(tempMC.getDepth());

           

          after you record that number (which will probably be something like -27,322), remove tempMC and that trace code and add:

           

          mc.swapDepths(the number you recorded)