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

ActionScript Object Explosion with Gravity Flash Effect

This Flash ActionScript Particle System tutorial is almost the same as the first tutorial except that the football object explode or break on the square object.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

This flash actionscript particle system tutorial is quite similar to the first one. In this flash explosion effect tutorial the football object explode or break into number of smaller balls when fall on the square block. Gravity is added to the broken smaller ball objects so that they will fall down when their energy is used up.

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

Flash ActionScript Codes:

// Use ENTER_FRAME event to fire action for every frame.
stage.addEventListener(Event.ENTER_FRAME, dropBall);

 

function dropBall(evt:Event):void {

// Keep track the location of the ball:
// y-Position of Block = 280
// Height of Block = 20
// y-position of Block's surface = 270
// Dia of Football = 40
// Radius of Football = 20
// Point the football touch the Block = 270 - 20 = 250

if (ball_mc.y < 250) {

ball_mc.y += 4;
} else {
ball_mc.visible = false;
block_mc.visible = false;

// Explode the football when touch the square block
stage.addEventListener(Event.ENTER_FRAME, ballBreaking);


}

}


//Call the dropBall function when movie starts.
//Therefore the football will start moving when movie starts.
dropBall(null);

// Declare number of small balls to born when explode
var numOfBall:uint = 30;

// Create an Array to hold the balls
var ballArray:Array = new Array();

// Creates 30 balls on the stage.
for (var i:uint = 0; i < numOfBall; i++) {

// Create a new Football
// Remember to set linkage in Movie Library
var ball:Ball = new Ball();

// Add the Football to the stage
addChild(ball);

// Assign start location of Ball
// Align with the surface of Block
ball.x = 256;
ball.y = 260;

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

// We don't want to see the Stars when newly added to the stage
ball.visible = false;

// Assign random velocity (y-axis) to the Ball
// Math.random returns value between 0 - 1
// i.e.
// Minimum value = 0 - 5 = -5
// Maximum value = 4 - 5 = -1
// Summary:
// yVelocity returns value between -5 to -1
ball.yVelocity = Math.random() * 4 - 5;

// xVelocity returns value between -3 to 3
ball.xVelocity = Math.random() * 6 - 3;

// Put Football into ballArray Array to be used later for animation
ballArray.push(ball);

}


function ballBreaking(evt:Event):void {
// Animate the balls one by one that hold in the Array
for (var i = 0; i < ballArray.length; i++) {

var ballParticles = ballArray[i];

// Set the Fotball visible again
ballParticles.visible = true;

// Footballs seems breaking from the Block's surface
ballParticles.y += ballParticles.yVelocity;
ballParticles.x += ballParticles.xVelocity;

// Add Gravity to balls so that they will bounce up at beginning
// then fall down when going up energy is finished.
ballParticles.yVelocity += 0.06
//trace(ballArray[1].yVelocity);

// If the Football move out the stage
if ( (ballParticles.x > 550) || (ballParticles.x < -40) || (ballParticles.y > 420) || (ballParticles.y < -40) ) {

// Stop the balls
ballParticles.xVelocity = 0;
ballParticles.yVelocity = 0;

}
}

}

Download Flash Source File:

Flash Source File The source code can be download at the end of this tutorial series.

Remarks:

This Flash ActionScript tutorial shows how to create a broken or explosion flash effect of an object. Gravity effect is added to the broken sobjects so that they will fall down when their energy is used up.