Skip navigation
Currently Being Moderated

Edit ActionScript to be behind other layers?

Jul 16, 2012 12:57 PM

Tags: #cs5 #help #flash #cs5.5 #3.0 #action_script_3 #actionscript #layer #layers #flash_cs5.5 #order #animation #actionscript3 #actions #snow #question #snowfall

I used some ActionScript to create a snow effect for my flash animation. Right now, the snow falls in front of my other layers, and sending to back isn't working. I'll post the ActionScript below.

 

I have a treeline background, with snow falling on top of that. I have pieces of a logo flying in, and I want that to be OVER the snow. Currently, when I play the animation, all I can see is the treeline and snow, and I'm guessing the logo is flying together behind it.

 

Can anyone be kind enough to point out how I can get this done? Thanks so much.

 

 

 

Snowfall ActionScript that I used (not mine) :

 

 

 

 

var snowflakes:Array = new Array();

var snowflakeProps:Dictionary= new Dictionary(true);

var max_snowsize:Number = .04;

// pixels

var snowflakesCnt:Number = 900;

var oheight:Number;

var owidth:Number;

init();

function init():void {

 

          owidth = width;

          oheight = height;

          // quantity

          for (var i:int=0; i<snowflakesCnt; i++) {

 

                    var t:MovieClip = new SnowFlake();//

                    t.name = "snowflake"+i;

 

                    t.alpha = .2+Math.random()*.6;

                    t.x = -(owidth/2)+Math.random()*(1.5*owidth);

                    t.y = -(oheight/2)+Math.random()*(1.5*oheight);

                    t.scaleX = t.scaleY=.5+Math.random()*(max_snowsize*10);

                    var o:Object = new Object();

                    o.k = 1+Math.random()*2;

                    o.wind = -1.5+Math.random()*(1.4*3);

 

                    snowflakeProps[t] = o;

 

                    addChild(t);

                    snowflakes.push(t);

          }

          addEventListener(Event.ENTER_FRAME, snowFlakeMover);

}

function shakeUp():void{

          for (var i:int=0; i<snowflakes.length; i++) {

                    var t:MovieClip = snowflakes[i] as MovieClip;

                    t.x = -(owidth/2)+Math.random()*(1.5*owidth);

                    t.y = -(oheight/2)+Math.random()*(1.5*oheight);

          }

}

function snowFlakeMover(evt:Event):void {

          var dO:MovieClip;

          var o :Object;

          if(visible && parent.visible){

          for (var i:int = 0; i < snowflakes.length; i++) {

                    dO = snowflakes[i] as MovieClip;

                    o = snowflakeProps[dO];

                    dO.y += o.k;

                    dO.x += o.wind;

                    if (dO.y>oheight+10) {

 

                              dO.y = -20;

 

                    }

                    if (dO.x>owidth+20) {

 

                              dO.x = -(owidth/2)+Math.random()*(1.5*owidth);

                              dO.y = -20;

 

                    } else if (dO.x<-20) {

 

                              dO.x= -(owidth/2)+Math.random()*(1.5*owidth);

                              dO.y = -20;

                    }

 

          }

          }

}

 
Replies
  • kglad
    63,053 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 16, 2012 1:06 PM   in reply to drb0b1

    add your snow to a depth above your tree but below your logo.

     

     

     

     

    var snowflakes:Array = new Array();

    var snowflakeProps:Dictionary= new Dictionary(true);

    var max_snowsize:Number = .04;

    // pixels

    var snowflakesCnt:Number = 900;

    var oheight:Number;

    var owidth:Number;

    init();

    function init():void {

     

              owidth = width;

              oheight = height;

              // quantity

              for (var i:int=0; i<snowflakesCnt; i++) {

     

                        var t:MovieClip = new SnowFlake();//

                        t.name = "snowflake"+i;

     

                        t.alpha = .2+Math.random()*.6;

                        t.x = -(owidth/2)+Math.random()*(1.5*owidth);

                        t.y = -(oheight/2)+Math.random()*(1.5*oheight);

                        t.scaleX = t.scaleY=.5+Math.random()*(max_snowsize*10);

                        var o:Object = new Object();

                        o.k = 1+Math.random()*2;

                        o.wind = -1.5+Math.random()*(1.4*3);

     

                        snowflakeProps[t] = o;

     

                        addChild(t);  // change this to something like addChildAt(t,1).  you need to check the depth of your tree and logo to determine where to add your snow.

    // or create an on-stage movieclip that's between your tree and logo and add the snow to that movieclip, like:

    // middle_mc.addChild(t);

    // and there are other ways to handle this.

                        snowflakes.push(t);

              }

              addEventListener(Event.ENTER_FRAME, snowFlakeMover);

    }

    function shakeUp():void{

              for (var i:int=0; i<snowflakes.length; i++) {

                        var t:MovieClip = snowflakes[i] as MovieClip;

                        t.x = -(owidth/2)+Math.random()*(1.5*owidth);

                        t.y = -(oheight/2)+Math.random()*(1.5*oheight);

              }

    }

    function snowFlakeMover(evt:Event):void {

              var dO:MovieClip;

              var o :Object;

              if(visible && parent.visible){

              for (var i:int = 0; i < snowflakes.length; i++) {

                        dO = snowflakes[i] as MovieClip;

                        o = snowflakeProps[dO];

                        dO.y += o.k;

                        dO.x += o.wind;

                        if (dO.y>oheight+10) {

     

                                  dO.y = -20;

     

                        }

                        if (dO.x>owidth+20) {

     

                                  dO.x = -(owidth/2)+Math.random()*(1.5*owidth);

                                  dO.y = -20;

     

                        } else if (dO.x<-20) {

     

                                  dO.x= -(owidth/2)+Math.random()*(1.5*owidth);

                                  dO.y = -20;

                        }

     

              }

              }

    }

     
    |
    Mark as:
  • kglad
    63,053 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 20, 2012 8:08 AM   in reply to drb0b1

    you can use getChildIndex() to check the depth of any display list object:

     

    getChildIndex(your tree movieclip)

    getChildIndex(your logo movieclip)

     
    |
    Mark as:
  • kglad
    63,053 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 20, 2012 10:23 AM   in reply to drb0b1

    you can use:

     

    addChildAt(your tree movieclip,0);  // to position your tree bottom-most

     

    // and every time you add some snow use:

     

    addChild(t); // adds your snow on top of everything

    addChild(your logo movieclip);  // (re)adds your logo on top of everything

     
    |
    Mark as:
  • kglad
    63,053 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 20, 2012 11:22 AM   in reply to drb0b1

    use:

     

    addChild(your tree movieclip); 

     

    var snowflakes:Array = new Array();

    var snowflakeProps:Dictionary= new Dictionary(true);

    var max_snowsize:Number = .04;

    // pixels

    var snowflakesCnt:Number = 900;

    var oheight:Number;

    var owidth:Number;

    init();

    function init():void {

     

              owidth = width;

              oheight = height;

              // quantity

              for (var i:int=0; i<snowflakesCnt; i++) {

     

                        var t:MovieClip = new SnowFlake();//

                        t.name = "snowflake"+i;

     

                        t.alpha = .2+Math.random()*.6;

                        t.x = -(owidth/2)+Math.random()*(1.5*owidth);

                        t.y = -(oheight/2)+Math.random()*(1.5*oheight);

                        t.scaleX = t.scaleY=.5+Math.random()*(max_snowsize*10);

                        var o:Object = new Object();

                        o.k = 1+Math.random()*2;

                        o.wind = -1.5+Math.random()*(1.4*3);

     

                        snowflakeProps[t] = o;

     

                        addChild(t); 

    addChild(your logo movieclip);

                        snowflakes.push(t);

              }

              addEventListener(Event.ENTER_FRAME, snowFlakeMover);

    }

    function shakeUp():void{

              for (var i:int=0; i<snowflakes.length; i++) {

                        var t:MovieClip = snowflakes[i] as MovieClip;

                        t.x = -(owidth/2)+Math.random()*(1.5*owidth);

                        t.y = -(oheight/2)+Math.random()*(1.5*oheight);

              }

    }

    function snowFlakeMover(evt:Event):void {

              var dO:MovieClip;

              var o :Object;

              if(visible && parent.visible){

              for (var i:int = 0; i < snowflakes.length; i++) {

                        dO = snowflakes[i] as MovieClip;

                        o = snowflakeProps[dO];

                        dO.y += o.k;

                        dO.x += o.wind;

                        if (dO.y>oheight+10) {

     

                                  dO.y = -20;

     

                        }

                        if (dO.x>owidth+20) {

     

                                  dO.x = -(owidth/2)+Math.random()*(1.5*owidth);

                                  dO.y = -20;

     

                        } else if (dO.x<-20) {

     

                                  dO.x= -(owidth/2)+Math.random()*(1.5*owidth);

                                  dO.y = -20;

                        }

     

              }

              }

    }

     
    |
    Mark as:
  • kglad
    63,053 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 20, 2012 1:22 PM   in reply to drb0b1

    click file>publish settings>swf and tick "permit debugging". retest.

     

    copy and paste the complete error message and indicate the first line number mentioned in the error message.

     
    |
    Mark as:
  • kglad
    63,053 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 20, 2012 3:22 PM   in reply to drb0b1

    right click whatever you think is Bitmap2, click convert to symbol, choose MovieClip and click ok.  in the properties panel assign the instance name tree_mc.

     

    shift-left click whatever your think is Object1,..,Object4 to select them all, right click, click convert to symbol, choose MovieClip and click ok.  in the properties panel assign the instance name logo_mc.

     

    remove the code you added and then add the following to confirm you followed the above steps correctly:

     

    trace(tree_mc);

    trace(logo_mc);

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points