Saturday, January 15, 2011

Smoke and Flames with actionScript 3.0

Ahhh, Quest for fire! Good song by the way..

Smoke/Flames Script using AS 3.0. It uses a mixture of .png's as well as Flash's (CS) blending modes to create a realistic fire effect similarly found in popular FX programs like Particle Illusion. All this creates flames that not only look real and respond to mouse movements, but is also completely random in form.

I used different brush effect within PS to create .png's to import to Flash.

The script is very adaptable and greatly commented. For the adventurous, one could create other fun and realistic elements from this script.

Enjoy! ~kb

On Scene 1 add an actions layer and add the following meat!

F9 >AS 3.0

// an array in which to store our particles
var particles:Array = new Array();

// add a blur filter to our stage
filters = [new BlurFilter(0,0,0)];

// call frameLoop every frame
addEventListener(Event.ENTER_FRAME, frameLoop);

function frameLoop(e:Event)
var particle:Particle;

// loop through the array of particles and update each one
for(var i : int = 0; i < particle =" new" yvel =" 0;" drag =" 1;" gravity =" randRange(-0.5,-0.4);" scalex =" particle.clip.scaleY" shrink =" +1;" fade =" 0.015;" alpha =" randRange(0.4,0.6);">40)
particle = particles.shift();



// returns a random value between min and max
function randRange(min:Number, max:Number)
return Math.random()*(max-min)+min;

Then set up your movieClips imported by PS png's

Then on set a scene up for the smoke/spark/flame movieClips added on separate layers, then add an actions layer and add the following code.

sparks.x *= Math.random()+0,-5;
smoke.x = smoke.y = Math.random()*-8,+8;
flame.x = flame.y = Math.random()*-4,+4;

smoke.scaleX = smoke.scaleY = Math.random()+0.2, +0.1;
flame.scaleX = flame.scaleY = Math.random()+0.6, +0.65;
sparks.scaleX = sparks.scaleY = Math.random()-0.001, +0.001;

sparks.rotation *= Math.random()+0,+5;
flame.rotation *= Math.random()+0,+5;
smoke.rotation *= Math.random()+0,+90;

That's it!! Publish this baby and let some magic roll!

see the file in action at

stay tuned for more!

No comments:

Blog Archive