Falling Snow AS3 code question...
I have found some code for falling snow that I like and have successfully placed it into my Flash file as a Class. (This is all new to me, so bare with me please.) It looks great, however, I want the snow to be in front of a background image that is a city skyline, and I also want to have a movie clip layer that is in front of the snow that consists of images flying around the page, quotes, etc. Can I change this existing code to work that way? Or can I place it on it's own layer instead of using it as a Class? Any help would be greatly appreciated.
Thanks!
Here's the code:
/* Main Class */
/* Developed by Carlos Yanez */
/* Image: http://www.flickr.com/photos/andyarmstrong/89441086/ */
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Snow extends MovieClip
{
private var flakesVector:Vector.<MovieClip> = new Vector.<MovieClip>();
private var timer:Timer = new Timer(2000);
public function Snow(speed:int = 3, flakesNumber = 100):void
{
for(var i:int = 0; i < flakesNumber; i++)
{
var flake:Snowflake = new Snowflake();
flake.vel = (Math.random() * speed) + 0.5;
flake.xSpeed = Math.floor(Math.random() * (0.5 - -0.5 + 1)) + -0.5;
flake.scaleX = (Math.random() * 1) - 1.0;
flake.scaleY = flake.scaleX;
flake.x = Math.random() * stage.stageWidth;
flake.y = Math.random() * stage.stageHeight;
addChild(flake);
flakesVector.push(flake);
}
addEventListener(Event.ENTER_FRAME, fall);
timer.addEventListener(TimerEvent.TIMER, changeMovement);
timer.start();
}
private function fall(e:Event):void
{
for(var i:int = 0; i < flakesVector.length; i++)
{
flakesVector.x += flakesVector.xSpeed;
flakesVector.y += flakesVector.vel;
if(flakesVector.y > stage.stageHeight)
{
flakesVector.x = Math.random() * stage.stageWidth;
flakesVector.y = -flakesVector.height;
}
}
}
private function changeMovement(e:TimerEvent):void
{
for(var i:int = 0; i < flakesVector.length; i++)
{
flakesVector.xSpeed *= -1;
}
}
}
}
