Snow Effect Example 2

Please download the sources of Example 2. We will use the names of image files and configuration file
from this package.

1) Open the Components panel (Ctrl-F7 or Window>Components)

Components: Snow Effect

2) Drag the Snow Effect component to the Stage.
3) Adjust the Snow Effect instance. Enter "snow" to the instance name. Set X and Y to 0, width to 541 and height to 361.

4) Open the Actions panel (F9 or Window>Actions) and enter the following lines:

var mouseX0:Number = width/2;
var mouseY0:Number = 0;
var mouseX1:Number = mouseX;
var mouseY1:Number = mouseY;
var mouseEn:Boolean = true;
// init
stage.align = "TL";
stage.scaleMode = "noScale";
// load confuguration
var loader:URLLoader = new URLLoader();
loader.addEventListener("complete", complete);
loader.addEventListener("ioError", ioError);
var url:String = loaderInfo.parameters.configUrl;
if ((url == null)||(url == "")) url = "snow.xml";
loader.dataFormat = "text";
loader.load(new URLRequest(url));
// configuration was loaded
function complete(e:Event):void {
    var xml:XML = new XML(;
    var imgList:XMLList = xml.child("image");
    if (imgList.length() == 0) imgList = null;
    var numOfSnowflakes:Number = parseFloat(xml.@numOfSnowflakes);
    if (isNaN(numOfSnowflakes)) numOfSnowflakes = 1000;
    var blurCoeff:Number = parseFloat(xml.@blurCoeff);
    if (isNaN(blurCoeff)) blurCoeff = 0.3;
    var wind:Number = parseFloat(xml.@wind);
    if (isNaN(wind)) wind = 0;
    var gravity:Number = parseFloat(xml.@gravity);
    if (isNaN(gravity)) gravity = 0.4;
    mouseEn = (xml.@mouseEnabled == "true");
    snow.wind = wind;
    snow.gravity = gravity;
// load configuration error handler
function ioError(e:Event):void {
// if mouseEn==true add mouse
function enterFrame(e:Event):void {
    // convert mouse position to wind and gravity
    if ((mouseEn)&&((mouseX != mouseX1)||(mouseY != mouseY1))){
        snow.wind = -(width/2 - (mouseX1=mouseX))/80;
        snow.gravity = 0.4 + 3*(mouseY1=mouseY)/height;
// resize event handler
function onResize(e:Event):void {
    snow.width = stage.stageWidth;
    snow.height = stage.stageHeight;

5) This movie plays the snow animation over a simple slide show.
By default it loads the configuration file snow.xml. You can specify an other configuration file in the parameter configUrl provided to the loaded SWF file.

You can see the example of configuration file below:

<?xml version="1.0" encoding="utf-8" ?>
<data numOfSnowflakes="1000" wind="0" gravity="0.4"
			mouseEnabled="false" blurCoeff="0.3">
    <image url="images/258709tt.jpg" duration="5" />
    <image url="images/258721tt.jpg" duration="5"
			wind="-1" gravity="1.0" />
    <image url="images/258746tt.jpg" duration="5"
			wind="0" gravity="0.4"/>

The line <data numOfSnowflakes="1000" wind="0" gravity="0.4" mouseEnabled="false" blurCoeff="0.3">
describes an initialization data for the Snow Effect.
Other lines specify slide show images.

Test this animation (Ctrl-Enter or Control>Test Movie)

You need Adobe Flash Player v.10 or above.

Install Adobe Flash player