ActionScript 3.0 Particle Systems #2: Snow Effect

More ActionScript, much like the previous one in execution…

Source code and flash files after the jump for those who want ’em.

Flash File (ActionScript 3.0) Code:

ActionScript 3.0 Snowflake Class Code:

Adobe Flash CS4 files can be found: here

8 thoughts on “ActionScript 3.0 Particle Systems #2: Snow Effect”

  1. That is quite impressive stuff you’ve learned there, keep it up!

    And this one is quite apt too, since it is snowing here (again!) right now.

      1. I like the snow effect, question I have what’s the difference in the flash file at the top and the action script one. also if I wanted to accumulate snow ontop of the cabin or the mountains along with it snowing , how can I do that and combine the classes into the one package.

        thanks

        Jason

        1. Hi Jason,

          The difference between the flash file and the class is that the flash file code is placed on a keyframe of the timeline in the main .FLA file, while the class is a standalone file that describes the properties and functions related to a single snowflake, which you can then use to create as many snowflakes as you’d like. I think you can place the snowflake code inside the .fla code (above it), but it’s best to keep classes in separate files to cut down on the code getting bulky (and as such difficult to work with) and so you can re-use the code in other projects with minimum hassle.

          You’d need to make significant changes to the code for the snow to accumulate on top of anything depicted in the background image – if you really want to do it, start with just getting the snow to accumulate at the bottom of the stage by checking if it’s moved off the bottom of the stage or collided with another “locked” snowflake, at which point you just move the colliding snowflake back one frames worth of movement and lock it in place, or just lock it in place where it collided depending on how you want it to work…

          Collision detection is pretty easy in AS3 as you get the AS3 hitTestObject function to use (example: http://www.foundation-flash.com/tutorials/as3hittesting/) as well as the hitTest function for per-pixel collision detection (which I’ve covered in other flash articles such as this: variable-size-particle-collisions ) when you get more confident with AS3.

          With no offense meant, from your question it’s possible that you might be biting off a little bit more than you can chew with snowflake accumulation, so if you find you’re struggling with it, just try and concentrate on getting each aspect required individually until you feel you’re able to put it all together. i.e.:
          – Get comfortable adding and manipulating properties of classes
          – Make sure you can add a property to a class which will lock the object in place when you set it,
          – Make sure you can detect a collision between two objects
          – Make sure you can lock two objects in place once they collide
          – Make sure you can detect a collision, take one step back, and then lock objects in place once they collide etc.

          Hope this helps,
          r3dux

  2. Thank a lot!

    I modified some variables in “ActionScript 3.0 Snowflake Class Code” in order to create an upping bubbles effect.

    Enjoy it!!!

  3. i dont know how to get rid of the control message: press any key..etc

    // Create our controls message, center it and add it to the screen
    var msg:ControlsMessage = new ControlsMessage();
    msg.x = stage.stageWidth / 2;
    msg.y = stage.stageHeight / 2;
    addChild(msg);

    1. Try this: Snow-CtrlMsg+Banner.zip

      Obviously change the banner =P

      If you want the snow to be in front of the banner then just delete the Banner symbol and post-it-note.png from the library, then delete the below code from the bottom of the actions layer:

      Finally, just pick File | Import | Import to Stage… and point it at your banner of choice.

Leave a Reply

Your email address will not be published.