XML Image Gallery with Falling Pictures (Snow Effect)
| Category | : Flash | Views | : 28623 | ||
| Version | : 8 | Rating | : | ||
| Type | : Text | Source File | : xml-image-gallery-with-falling-pictures.zip | ||
| Result | : See the result | ||||
The last thing for this part of the code is to get a random direction for every "frame" MC:
//Random number between -1 and 1
var dir = Math.random() * 2 - 1;
//The code below will run if "dir" equals to 0 and will run until "dir" is different than 0
while(dir == 0)
{
//Get another random number until its different than 0
dir = Math.random() * 2 - 1;
}
Now we just need to code the MC, so open the actions for the "frame" MC's instance and paste:
onClipEvent(load)
{
//Import libraries need for the animation
import mx.transitions.Tween;
import mx.transitions.easing.*;
//Create a function called "reset()" to reuse the code below when necessary
function reset()
{
//Random scale between 3 and 9
this._xscale = this._yscale = Math.random() * 6 + 3;
//Random alpha 50 to 100
this._alpha = Math.random() * 50 + 50;
//Rotation 0º to 360º
this._rotation = Math.random() * 360;
//Random position above the stage, between -200 and -100
this._y = Math.random() * 100 - 200;
//Random position for the _x coordinate
this._x = Math.random() * Stage.width;
//Get random _y speed, 2 to 7
yspeed = (Math.random() * 5 + 2);
//Random _x speed, 1 to 5. Speed will be negative if the variable "dir" is negative
xspeed = (Math.random() * 4 + 1) * _root.dir;
//Whether this image is selected or not
select = false;
}
//Call the function "reset()" for the first time
reset();
}
The MC won't fall yet, so paste this:
onClipEvent(enterFrame)
{
//If the images are loaded and this MC is not selected
if ((!select) && (_root.ready))
{
//Move on the _x coordinate
this._x += xspeed;
//Move on the _y coordinate
this._y += yspeed;
}
//If this MC left the screen in any direction, call the function reset()
if(this._y > Stage.height)
{
reset();
}
if(this._x < -50)
{
reset();
}
if(this._x > Stage.width + 50)
{
reset();
}
}
![]() |
![]() |
![]() |
![]() |
![]() |




