Snowflake

http://dreamsyntax.org/patterns/swf/parallax_snowflake.swf

In Flash

 * Inside your flash file, you draw something, a dot, a seahorse, anything you fancy.
 * Hit F8, make it into a symbol movieclip.
 * In the library panel, right mouse click it and edit the properties.
 * Make sure your snowflake has a className set to it.




 * Now enter the following code in the first frame of the timeline. This creates the snowflakes themselves! Because the snow class that follows will just handle the appearance and movement of it, you need to set your snowflakes here.

 function createFlakes:void{ var sFlake:SnowFlake = new SnowFlake; addChild(sFlake); } var numFlakes:int = 500;

for(var i:int;i

I have chosen this tutorial as reading this will help you understand better how a flash class works.

SnowFlake.as
NOTE THE LETTER CASE OF THE FILENAME! IT IS CRUCIAL YOU SPELL IT THE SAME OR FLASH WILL NOT REFER BACK TO THE CLASS!

 // HEAVILY COMMENTED SNOW CLASS IN AS3 // based on pixelfumes' snow class: http://pixelfumes.blogspot.com/2006/11/actionscript-3-snow-storm-class.html // ==================================================================================

package{

// these are the flash packages to import in	import flash.display.MovieClip; import flash.events.*; import flash.filters.BlurFilter;

import fl.transitions.*; import fl.transitions.easing.*; public class SnowFlake extends MovieClip{ // these are the settings, note their position in this file! - within the SnowFlake class but right at the top! // always declare your variables first, within the class and at the top, above the constructor private var speedMultiplier:int = 10; private var speedVariMultiplier:int = 5; private var speed:uint = Math.random*speedMultiplier; private var speedVariation = Math.random*speedVariMultiplier+1; private var viewWidth:int = 550; private var viewHeight:int = 500; private var drift:int; // private vars can only be used within SnowFlake class // int = integer (whole numbers, plus and minus) // uint = unsigned integer (whole numbers, no minus) -- speed always has to be an unsigned/positive number! // Math.random = generates a random number between 0 and 1. to make it more usable, you multiply it with other things!

// this next function is the "constructor" - it sets everything off!! function SnowFlake{ setSpeed(speed); readyFlake; moveMe; }

// these are the "arguments". they are what the constructor are calling. it helps divide things into neat segments.

// setSpeed - sets the speed private function setSpeed(n:uint):void{ this.speed = (n * speedVariation)+1; }

// readyFlake - sets up the snowflakes up! puts them in place! private function readyFlake:void{ // gotta get the Drift value so you can use it to calculate the blur getDrift; // assign the snowflake position based from the size of the stage and a random factor this.y = Math.random*viewHeight*-1; this.x = Math.random*viewWidth; // you create a new BlurFilter called bf			// BlurFilter(blurX, blurY,quality) // blurX - amount to blur horizontally (0-255) // blurY - amount to blur vertically (0-255) // quality - number of times to apply filter (BIGGER NUMBER, MORE BLUR) var bf:BlurFilter = new BlurFilter(drift*2,speed/2,2); this.filters = [bf]; if(speed/2 < speedVariation){ // if the speedVariation is more than half of the speed, then make the snowflake smaller this.scaleX = this.scaleY = 0.5; }		}		// getDrift - sets a drift value which knows when to go back when it drifts too far in one direction! private function getDrift:void{ drift = Math.random*3; var driftDirection:int = Math.random*10; if(driftDirection < 5){ drift *= -1; }		}

// moveMe - adds an event listener that on every single frame, calls the next function everyFrame private function moveMe:void{ this.addEventListener(Event.ENTER_FRAME,everyFrame); }

// everyFrame - at each frame it assigns the speed and drift values to each snowflake private function everyFrame(e:Event):void{ this.y += speed; this.x += drift; if(this.y > viewHeight || this.x < 0 || this.x > viewWidth){ readyFlake; }		}	} } 

SnowFlake.as
With no comments - just code:

 package{

import flash.display.MovieClip; import flash.events.*; import flash.filters.BlurFilter;

import fl.transitions.*; import fl.transitions.easing.*; public class SnowFlake extends MovieClip{ private var speedMultiplier:int = 10; private var speedVariMultiplier:int = 5; private var speed:uint = Math.random*speedMultiplier; private var speedVariation = Math.random*speedVariMultiplier+1; private var viewWidth:int = 550; private var viewHeight:int = 500; private var drift:int; function SnowFlake{ setSpeed(speed); readyFlake; moveMe; }

private function setSpeed(n:uint):void{ this.speed = (n * speedVariation)+1; }

private function readyFlake:void{ getDrift; this.y = Math.random*viewHeight*-1; this.x = Math.random*viewWidth; var bf:BlurFilter = new BlurFilter(drift*2,speed/2,2); this.filters = [bf]; if(speed/2 < speedVariation){ this.scaleX = this.scaleY = 0.5; }		}		private function getDrift:void{ drift = Math.random*3; var driftDirection:int = Math.random*10; if(driftDirection < 5){ drift *= -1; }		}

private function moveMe:void{ this.addEventListener(Event.ENTER_FRAME,everyFrame); }

private function everyFrame(e:Event):void{ this.y += speed; this.x += drift; if(this.y > viewHeight || this.x < 0 || this.x > viewWidth){ readyFlake; }		}	} } 