Well, I have been really busy lately working on various projects (to be posted here soon hopefully) and as this is my first post in a while I thought why not keep in tune with the current season and make it a festive one.
As the new Flash player 10 enables the use of 3D space I thought it fitting to create a snowfall in 3D to make it feel as if you really are out in the bleak cold of winter on a cold christmas morning…….This one is created exclusivley for FP10 so you’ll need that installed in your browser to view this and the source files are Flash CS4 / Flex only….?!
The script makes use of the Z property in the new flash API and creates a good feeling of depth. As you can see from the script, the Vector3D class is initiated to add some good X, Y & Z figures to the flakes and gives them some good random motion.
-
private function init(e:Event):void {
-
startX = (-stage.stageWidth / 2) + (Math.random() * stage.stageWidth);
-
this.scaleX = Math.random() * .9;
-
this.scaleY = this.scaleX;
-
this.x = startX;
-
this.y = -(Math.random() * (stage.stageHeight + 200));
-
this.z = -500 + (Math.random() * 800);
-
vector = new Vector3D(0, 0, 0);
-
vel = new Vector3D((Math.random()*1.5), -3, (Math.random()*1.5), (Math.random()*10));
-
-
}
The flake class creates the flake from the movieclip linked to it in the Flash CS4 library and gives it some random size, position as well as movement. This is then added in the main document class during the “FOR” loop along with 299 of its brothers and sisters. An ENTER_FRAME event listener is added after this and calls the updateFlake function of each individual snow flake which dictates their movements. As this is called each frame the movements of all 300 flakes are created each frame.
-
public function updateFlake():void{
-
this.x -= vel.x;
-
this.y -= vel.y;
-
this.z -= vel.z;
-
var dx:Number = vector.z - this.z;
-
var dy:Number = vector.y - this.y;
-
var b:Number = (Math.sqrt(dx*dx + dy*dy) / 100) + 7;
-
if(b <0){
-
b = Math.abs(b);
-
}
-
blur = new BlurFilter(b, b, 3);
-
this.filters = [blur];
-
if(this.y> (stage.stageHeight + 100)){
-
this.y = -100;
-
this.x = startX;
-
this.z = -500 + (Math.random() * 800);
-
}
-
}
Once they reach a certain point on the stage they are immediately moved back to their starting point, thus creating a continual loop of soft white fluffy floaty snow……..:)

Posted in
Tags: 



![Validate my RSS feed [Valid RSS]](http://www.ultravisual.co.uk/blog/images/valid-rss.png)


Hello, the download link is broken.
Congratulations by the article.
Abraços.
Hello back…..works fine for me……try again. Thanks
Great tutorial many thanks..