Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

Raining Flash ActionScript Particle System

Step 2: Create Rain Effect Animation

Like other Flash Particle System with ActionScript 3, the second step is try to animate the rain drop particles to create the raining effect animation.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

In previous step of raining particle with Flash ActionScript, all rain drop particles were created on the stage. Like other Flash ActionScript Particle System tutorials, the next step is:

- animate the rain drop particles,

- resize the rain drops particles randomly,

- set random alpha to rain drops particle.

Since we are quite familar with the Flash ActionScript Particle System, we animate the rain drop particles, resize rain drop particles and set alpha of rain drop particles at the same time.

The Flash Movie of this Flash ActionScript Rain Particle System tutorial is shown as above.

Flash ActionScript Codes:

// Declare number of Rain Drops
var numOfRain:uint = 20;

// Create an Array to hold the Rain Drops
var rainArray:Array = new Array();

// Creates 20 Rain Drops on the stage.
for (var i:uint = 0; i < numOfRain; i++) {

// Create a new Rain drop
// Remember to set linkage in Movie Library
var rain:RainDrop = new RainDrop();

// Add the Rain Drop to the stage
addChild(rain);

// Assign start location of Rain Drops
// x-axis: Line within the cloud
// y-axis: between cloud and ground
rain.x = ( cloud_mc.x - (cloud_mc.width / 2) + 10 ) + Math.random() * 165;
rain.y = cloud_mc.y + 15 + Math.random() * 300;

// Assign random alpha to Rain Drop
// Math.random returns value between 0 - 1
// i.e.
// Minimum value = 0.4 + 0 = 0.4
// Maximum value = 0.4 + 0.6 = 1.0
// Summary:
// Assign random alpha between 0.4 and 1.0
rain.alpha = 0.4 + Math.random() * 0.6;

// Assign random scale to Rain drop
// Math.random returns value between 0 - 1
// i.e.
// Minimum value = 0.3 + 0 = 0.3
// Maximum value = 0.3 + 0.3 = 0.6
// Summary:
// Assign random scale between 0.3 and 0.6
rain.scaleX = 0.3 + Math.random() * 0.3;
rain.scaleY = rain.scaleX;

// Assign random speed (y-axis) to the Rain Drop
// Math.random returns value between 0 - 1
// i.e.
// Minimum value = 2 + 0 = 2
// Maximum value = 2 + 3 = 5
// Summary:
// Math.random returns value between 2 - 5
rain.yVelocity = 2 + Math.random() * 3;

// Put Rain Drop into rainArray Array to be used later for animation
rainArray.push(rain);

}


// Add ENTER_FRAME Event to animate the Rain Drops
stage.addEventListener(Event.ENTER_FRAME, raining);

 

function raining(evt:Event):void {

// Animate the Rain Drops one by one that hold in the Array
for (var i = 0; i < rainArray.length; i++) {
var rainParticles = rainArray[i];

// Rain Drops falling down the y-axis
rainParticles.y += rainParticles.yVelocity;

// If the Rain Drops fall near stage's height (stage.stageHeight)
if (rainParticles.y > 350) {

// Locate the Rain Drop back to the Cloud (x-axis)
rainParticles.x = ( cloud_mc.x - (cloud_mc.width / 2) + 10 ) + Math.random() * 165;

// Locate the Rain Drop back to the Cloud (y-axis)
// 15 pixel down the center axis
rainParticles.y = cloud_mc.y + 15;

}
}

}

Remarks:

This Flash ActionScript rain particle system tutorial shows how to animate the rain drop particles, resize rain drop particles and set alpha of rain drop particles.