Actionscript 3 Snow Storm Class
It’s that time of year again. Winter is just about here and it is time for me to create snow. Last year I did a little demo of creating snow that sticks using Flash 8 and the BitmapData object. I thought that I would take a stab at doing an ActionScript 3 version. So with that said, here is an AS3 snow maker. The movie below obviously requires the Flash 9 player. I am using 1000 flakes in the example below. You can modify that in the FLA. I hope to update this and make it more dynamic in the near future but feel free to play with what is here.
Here is the class:
November 27th, 2006 at 4:36 pm
Yeah that’s cool
AS3 Rocks!
November 27th, 2006 at 5:11 pm
that is cool indeed. I didn’t know AS3 was out, gotta check it, then.
November 27th, 2006 at 5:54 pm
looks great.
November 28th, 2006 at 12:28 am
Purdy
)
Campbell A
November 28th, 2006 at 4:27 pm
Sweet! The killer app of AS3 – a new generation of snow renderers!
November 28th, 2006 at 6:34 pm
Sprites FTW!
November 29th, 2006 at 12:33 pm
how did you edit and compile this? i downloaded the fla file and and the class and used the public alpha of flash 9, but the compiler complains when i try to test from flash… any tips on getting started with as3?
November 29th, 2006 at 1:09 pm
I used the public alpha to compile. The FLA has one frame with the following on it:
function createFlakes():void{
var sFlake:SnowFlake = new SnowFlake();
addChild(sFlake);
}
var numFlakes:int = 1000;
for(var i:int;i<numFlakes;i++){
createFlakes();
}
December 9th, 2006 at 7:09 am
Wow thats insane
Ive just started using AS3 and Flex 2.0 in the last 3 days and just keep getting amazed at the possibilities.
Great work dude, keep em coming.
April 16th, 2007 at 7:21 pm
This looks really cool! but i can’t get it to work. (note, that i know very little about classes and/or as3)
Could you clarify if the sample works. Or is there something else that must be done. Thank you.
Great job!
April 16th, 2007 at 7:25 pm
Sam – are you using Flash CS3 or the Flash 9 ActionScript Preview to write your code? Can you send me your FLA? Thanks!
sgtpritchard at gmail.com
May 17th, 2007 at 11:15 pm
I was trying so hard to do something like this!
thx alot for this post.
but i also can’t get it to work :S
the class as is there and I’m using your flash file with Flash CS3, AS3 and Flash9 player, only one snowflake is on screen at 0,0
May 18th, 2007 at 12:47 am
It all works now!
I misspelled the file name when saving the class, it didn’t match the class name!
for Sam, make sure that you save the class code in “SnowFlake.as”
otherwise the fla won’t see it.
June 20th, 2007 at 5:49 pm
These comments have been invaluable to me as is this whole site. I thank you for your comment.
September 10th, 2007 at 5:37 pm
Dynamic snow, I love it! Great work.
-mL
http://knowledge.lapasa.net
October 23rd, 2007 at 8:11 am
Real lovely! The speed and smoothness is so life-like, ActionScript 3 really rocks. Looking at the Class it can easily be extended to accomodate more options such as color, rate and so on. Thanks a million, this class realy really is impressive.
Otuyelu
http://www.oroede.org
November 11th, 2007 at 6:42 pm
Very new to flash. Trying to run befor I can walk. How do I put the class file to the Flash file to get it to work. Any help Thanks.
November 11th, 2007 at 7:34 pm
Sorry for leaving my last comment twice. and with a bit of head scratching and a lot of googleing I’v sused it. It’s all to do with the class path init?
Thanks and keep up the good work.
November 24th, 2007 at 2:57 am
Awesome class! I have built a class called SnowStorm around it that both extends it and black boxes it. Simple instantiation, start/stop, and black-box access to properties.
I have had to make a few minor mods to the SnowFlake class to allow for this, but really didn’t change it much. Mods and new features include:
-Snowflake draws itself as a graphic instead of using a library movieclip. This makes it an independant class that does not need to load any library items from an FLA.
-Extended properties like size and color of snowflake, and speed variables so that they can be easily accessed as properties of the class (and all properties simply default so you do not have to set any).
-Added automatic stage-size detection, unless you override that by setting the viewWidth and viewHeight properties yourself.
-Added start/stop features to the snowfall, which can be passed a delay (in seconds) that it takes for the storm to get started. For example you could call begin(30) and the snowfall would increase slowly over 30 seconds until its going full on.
The code in the SnowStorm class is commented and I have also included an FLA to test it out with immediately.
Linking temporarily from my site because I don’t see a way to include code (or files) in the comments!
========================
SnowStorm.as
SnowFlake.as
SnowStormDemo.fla
SnowStormDemo.swf
========================
December 13th, 2007 at 7:07 pm
Shouldn’t you use Sprites instead of MovieClips for your SnowFlakes, because it would save a lot of memory since there are 1000 snowflakes.
March 3rd, 2009 at 5:19 pm
I’ve downloaded this and it isn’t working for me either. Hopefully you’re still available to help me with this issue. I have the package that looks like this:
package {
import flash.display.MovieClip;
import flash.events.*;
import flash.filters.BlurFilter;
public class SnowFlake extends MovieClip{
private var speedMultiplier:int = 5;
private var speedVariMultiplier:int = 10;
}
}
I’ve tested this in an external AS file as well as within the main timeline of my FLA. On publish I get Error:
1131: Classes must not be nested.
March 4th, 2009 at 9:37 am
Tobin, did you download the FLA (http://www.pixelfumes.com/blog/nov06/snowFlake.fla) above, create the Class (SnowFlake.as file) and assign a linkage to your flake in the library to use the SnowFlake class?
March 6th, 2009 at 3:53 pm
I’ll publicly embarrass myself and say that I didn’t grab all the code in the package above. I just now figured this out as I was redoing it for the nTH time. I appreciate you getting back to me. It works great! Thanks for posting this for us to use.
March 6th, 2009 at 4:08 pm
On another note. Is it possible to put something like this inside of a mask? If not, how do I reduce the size of it and move it’s location in the movie? Here’s my big problem: I need the snow to fall in an abnormal shape. Here is a screen capture of where the snow should fall. The tan box is actually a mask in my FLA and snow should fall only in that area.
http://www.TobinRogers.com/snowarea.png
Thanks again
March 6th, 2009 at 4:15 pm
Tobin, you should be able to mask or use this in any nested clip. Take a look inside of the .as file to tweak the borders of the snow.
April 19th, 2009 at 12:21 pm
I’m having a slight problem… is there anyway for the snow to stop, lets say, at little at the left side?
i’m quite new at this. any help would be appreciated
November 25th, 2009 at 8:50 am
Hi there,
I think I am way out my depth with this. Desperately trying to create a snow effect in CS3 AS3 and have never done anything like this before. Sorry if it sounds daft but I have downloaded the fla file. How do you create a class? Is that just pasting the code in the first frame of the animation? Sorry if this is silly question but I really am a beginner!
Please help!
Gem
November 25th, 2009 at 9:16 am
ah ok, have worked out how to make a class and have assigned a linkage to the file which it is recognising. I am now just getting a source error of
1114: The public attribute can only be used inside a package.