Page 2
//this point is where we have the snow
//coordinates, so we will use this to make
//hitTests later.
var hitPoint = new Point(hitBitmap.rectangle.x, hitBitmap.rectangle.y);
//the direction for the snow; 1 = right, -1 = left and 0 = none.
var dir = Math.round(Math.random() * 2) - 1;
//used to create new Movie Clips
i = 0
//call the function setInterval every 50 milliseconds.
setInterval(dropSnow, 50);
function dropSnow ()
{
//increase by 1
i++;
//attach new snow
_root.attachMovie("snow", "snow" + i, i);
}visibleBitmap doesn't include the limits we draw earlier just the accumulated snow.
hitBitmap includes both snow and limits and we will use it just to make hitTests.
We are going to use them on the Snow Movie Clip, so open the actions for the first frame of the snow and paste:
//libraries for objects
import flash.display.BitmapData;
import flash.geom.Matrix;
//random positions
this._x = Math.random() * 400;
this._y = Math.random() * 10 - 10;
//random speed to fall
var speed = Math.random() * 5 + 2
//random speed between 0 and 2; if "dir" is
//negative the speed will be negative too and
//the snow will go to the left, if its positive
//the snow will go to the right and if its equal
//to 0 the snow won?t move on the _x coordinate.
var Xspeed = (Math.random() * 2) * _root.dir
this.onEnterFrame = function()
{
//new point set to this Movie Clip?s coordinates
var myPoint = new Object();
myPoint.x = this._x;
myPoint.y = this._y;
//if the "hitBitmap" hits with "myPoint" on the coordinates
//of "_root.hitPoint"
if (_root.hitBitmap.hitTest(_root.hitPoint, 0, myPoint))
{
//new matrix use to draw the snow in the update hitBitmap
//and visibleBitmap
var drawMatrix:Matrix = new Matrix ();
//this set the drawing location to our coordinates, so when we
//draw this on the bitmaps it will draw on our current location
drawMatrix.translate(this._x, this._y);
//draw this Movie Clip on the bitmaps using the location we set
//on the matrix object
_root.hitBitmap.draw(this, drawMatrix);
_root.visibleBitmap.draw (this, drawMatrix);
//remove the Movie Clip
this.removeMovieClip();
}
//Move the Movie Clip down if we didn?t hit anything
this._y += speed;
//move the Movie Clip left or right; if Xspeed is 0 the
//Movie Clip wont move right or left.
this._x += Xspeed;
//if the Movie Clip didn?t hit anything and left the screen
if (this._y > 500)
{
//remove Movie Clip
this.removeMovieClip();
}
}snow effect. Posted on 07/31/2008
Couldnt get it to work even when I copied your code. Obviously I am missing some information. The instructions were not clear enough for me and could not get it to work.






help
and feedback
latest
news
latest
forum entries