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:

28 Responses to “Actionscript 3 Snow Storm Class”

  1. JBOY Says:

    Yeah that’s cool :D

    AS3 Rocks!

  2. Anonymous Says:

    that is cool indeed. I didn’t know AS3 was out, gotta check it, then.

  3. dan Says:

    looks great.

  4. Anonymous Says:

    Purdy :o )

    Campbell A

  5. felix Says:

    Sweet! The killer app of AS3 – a new generation of snow renderers!

  6. Anonymous Says:

    Sprites FTW!

  7. Anonymous Says:

    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?

  8. Sarge Says:

    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();
    }

  9. Anonymous Says:

    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.

  10. sam Says:

    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!

  11. Sarge Says:

    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

  12. Bzouchir Says:

    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

  13. Bzouchir Says:

    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.

  14. Annerose Says:

    These comments have been invaluable to me as is this whole site. I thank you for your comment.

  15. Anonymous Says:

    Dynamic snow, I love it! Great work.

    -mL
    http://knowledge.lapasa.net

  16. Olumide Says:

    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

  17. Anonymous Says:

    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.

  18. Anonymous Says:

    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.

  19. Egg_Zap Says:

    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
    ========================

  20. zedia.net Says:

    Shouldn’t you use Sprites instead of MovieClips for your SnowFlakes, because it would save a lot of memory since there are 1000 snowflakes.

  21. Tobin Rogers Says:

    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.

  22. Ben Says:

    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?

  23. Tobin Rogers Says:

    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.

  24. Tobin Rogers Says:

    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

  25. Ben Says:

    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.

  26. Tiago Says:

    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 :)

  27. gemma Says:

    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

  28. gemma Says:

    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.

Leave a Reply