First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: alex winx | Website: http://www.winx.ws

Fire effect class (Fire)

by Winx

Before Flash 8 we made fire mainly by drawing flames and animating every frame. We have use some programs like Photoshop or other that make animated gifs or into Flash itself. We have achived big .fla size, little reality cos of repeating frames and even low customization. Thx to Ken Perlin and his Perlin noise function, gives mankind opportunity programatically to create nature texture like wood, water, marible, fire, clouds ..... Perlin noise function is added to Flash 8 AS2 which allow us to make realistic textures and by using Flash animating engine make them alive.

Making Fire programatically takes 4 planing steps:

First step is to make gradient source movie clip that make fire color and form :

//create gradient movie that form the fire color
"LinearRGB",0,new Point(0,0),null,width,height,90);//+15+10

Note: I have use function createCustomGradientMovieClip(..) from MovieEx class to create gradient Movie Clip but u can write your own.
Note: Use your own drawFunc to draw Fire form. In second step we need to create flame granularity texture. So we apply perlinNoise on a bmp that we have created before.

In second step we need to create flame granularity texture. So we apply perlinNoise on a bmp that we have created before.

//create perlin noise flame granularity

Then we need to create fire flames. For that we will use DisplacementMapFilter on a perlinNoiseBitmap and then apply on Fire gradient source movie clip.

//apply diplaced fire parts filter on gradient source (dying)
classObject.mcFire.fireGradientSource.filters =[classObject.fltDM];

Finnaly we will animating fire (make flames moves) by changing PerlinNoise noiseOffsets in EnterFrame or Interval events.

//make flames moving
classObject.noiseOffsets[i].x = classObject.noiseOffsets[i].x + classObject.noiseOffsetDeltas[i].x;
classObject.noiseOffsets[i].y = classObject.noiseOffsets[i].y + classObject.noiseOffsetDeltas[i].y;

Fire class contains:


function Fire(target:MovieClip,name:String,x:Number,y:Number,width:Number,height:Number,

target: reference - the object which the Tween targets
name: string - name of new fire MovieClip
x: number - x coord
y: number - y coord
width: number - height of new fire MovieClip
height: number - width of new fire MovieClip
rotation: number - rotation angle
sStrength: number - starting fire value (0)
spdRise: number - fire rising intensity time period
spdFall:Number - fire falling intensity time period
colors:Array - gradient fire color (u can set custom color let say blue Fire)
alphas:Array - alphs
ratios:Array - intensity
drawFunc:Function - fire form (make ur own) *see drawFireForm
EXAMPLE: "fire"

import effects.Fire;
import flash.geom.Point;
var f:Fire=new Fire(_root,"fire",150,220,100,100,30,5,10,10,[0x910000,0x910000,0x910000,0xFF9900,0xFFFD8A,0xFFFD8B,0xFFFDCB],[0,0,100,100,100,100,100],[0,70,90,110,148,250,255]);

» Level Advanced

Added: 2006-04-27
Rating: 3 Votes: 31
» Author
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.