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

Rain with Water Ripple Flash Effect Particle System

Step 3: Create Raining Animation

The flash raining effect is almost ready. It is time to animate the rain drop particles.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

In the Flash raining effect scenery, all rain drop particles were created , scaled and set alpha. Like other flash particle system, let's try to animate the rain drops to see the flash effect.

The first Flash Movie of this tutorial is shown as above.

Flash ActionScript Codes:

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

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

// Creates 10 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: 0 - 490
// y-axis: 0 - 200
rain.x = Math.random() * 490;
rain.y = Math.random() * 200;;

// 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 velocity (y-axis) to the Rain drop
// Math.random returns value between 0 - 1
// i.e.
// Minimum value = 6 + 0 = 6
// Maximum value = 6 + 5 = 11
// Summary:
// Math.random returns value between 2 - 5
rain.yVelocity = 6 + Math.random() * 5;

// Also assign a velocity in x-axis
// so that the rain will be dropped down with an angle
rain.xVelocity = 2;

// 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;
rainParticles.x += rainParticles.xVelocity;

// If the Rain Drops fall near stage's height (stage.stageHeight)

if (rainParticles.y > 280 + Math.random() * 230) {
// Locate the Rain Drop back to the Cloud (x-axis)
rainParticles.x = Math.random() * 490;

// Locate the Rain Drop back (y-axis)
// 10 pixel above the upper stage
rainParticles.y = -10;

}
}

}

Remarks:

This Flash ActionScript rain with water ripple effect tutorial shows how to animate the rain drop particles to create the raining effect.