- Package {
- Import Flash. Geom. matrix;//Color Gradient Class library pour
- The import Flash.display.sprite;//sprite class is a basic display list building block
- The Import Flash.display.gradienttype;//graphics class contains a set of methods that you can use to create vector shapes
- public class Mack_fire extends Sprite {//This class is the Spark prototype class
- private Var Fire:sprite;
- var Mymatrix:matrix;
- Public Function Mack_fire () {
- Fire = new Sprite ();//Initialize a movie clip
- Mymatrix = new Matrix ()//need to use the flash with the class, where the role is to make spark particles color gradient effect
- var boxwidth:int = 16;//Spark particle color gradient width high setting, below is height
- var boxheight:int = 16;
- var boxrotation:uint = variable used by math.pi/2;//color gradient
- var tx:int = Preliminary coordinates of 0;//movie clips
- var ty:int = 0;
- Mymatrix.creategradientbox (Boxwidth, Boxheight, Boxrotation, TX, ty);//below starts with the color Pay Value section, please refer to the specific usage of Creategradientbox
- var type:string = gradienttype.radial;
- var mycolors:array = [0xffff00, 0xffff00];//color gradient, white to white
- var myalphas:array = [1, 0];//transparency from, transparent to opaque
- var myralphas:array = [0, 255];
- var spreadmethod:string = "pad";
- var interp:string = "RGB";
- var focalptratio:number = 0;
- Fire.graphics.beginGradientFill (Type, Mycolors,myalphas,myralphas, Mymatrix, Spreadmethod, Interp, Focalptratio); Here please refer to the manual for Begingradientfill to understand
- Fire.graphics.drawCircle (8, 8, 8);//Make a circle, radius and center point coordinates, can refer to Drawcircle
- AddChild (fire);
- }
- }
- }
Fire.as:
- /***************ant qq:305033389******************/
- /************* Please support original, please open source code ****************/
- /********** please let more as enthusiasts have information to learn *************/
- /******** This work is my study work, not perfect works ***********/
- Package {
- Import Flash.display.MovieClip;
- Import Flash.events.EventDispatcher;
- Import flash.events.Event;
- Import Flash.display.BlendMode;
- Import Flash.filters.GlowFilter;
- Import Flash.geom.ColorTransform;
- public class Fire extends MovieClip {
- private Var Fires:mack_fire;
- Private Const MAXBALLS:INT = 60;//Spark Quantity
- Private Const MC_X:INT = stage.stageheight/2;//start of Fire x coordinates
- Private Const MC_Y:INT = stage.stageheight/2;//+stage.stageheight/4;//start of fire y-coordinate
- Private Const MC_MORE:INT = 1;//Vertex, the vertex of movement and transparency, 1 is completely opaque or not scaling,AS3 in 1 as the vertex, AS2 100
- Private Const MCY:INT = 1;//Move Up speed
- Private var i=1;//count variable
- private var obj_scal:array=new array ();//zoom variable Save arrays
- private var obj_fast:array=new array ();//move speed variable save arrays
- private var obj_action:array=new Array ();//horizontal Move Speed change variable
- private var obj_n:array=new Array ();//lateral Movement Direction control variable
- private var obj_s:array=new Array ();//transverse velocity control variable
- private var obj_gs:array=new Array ();
- private var obj_g:array=new Array ();//Color control variable
- Public Function Fire () {
- AddEventListener (EVENT.ENTER_FRAME,FIRE_MV);
- }
- Public Function FIRE_MV (event:event): void{
- var k = Math.random ()//Create the number, this variable determines the distance of the spark, has moved the range
- var scale:number = k? k:1;//creates a random number, which is less than 1, more than 0.
- fires = new Mack_fire ();
- Fires.scalex = Fires.scaley = Fires.alpha = scale;//component Scaling and transparency settings, based on the number of seconds above
- Obj_g[i] = 100;
- Obj_gs[i] = (1-scale+.2) *3;//defines a new array element, changing the color of the component
- Obj_fast[i] = Math.floor (scale*2);//longitudinal moving speed main variable
- Obj_action[i]= (Math.random () >0.5)? 1:-1;//longitudinal moving direction main variable
- Obj_scal[i] = 1-obj_fast[i]/10;//controls the scaling of the in-process spark
- Obj_n[i] = obj_s[i] = 1;
- fires.x= mc_x;//defines the horizontal axis generated by the spark
- Fires.y= mc_y;//defines the ordinate that sparks produce
- Fires.blendmode = blendmode.add;//This part is the focus of pure code sparks, color overlay. Make the Sparks and sparks look more sleek. Without this part, the effect of the fire simply does not set
- Fires.name = "Fire" +i;//defines the name of a spark, which is used below through Getchildbyname. This is a stupid way. Remember that there used to be a friend without definition or use.
- AddChild (fires);
- for (var n:int = 1; n<maxballs; ++n) {
- var m=getchildbyname ("Fire" +n);//Use the Spark movie clip defined above
- if (m) {
- var colorinfo:colortransform = m.transform.colortransform;//Define color controller
- var xx=obj_gs[n]*2;
- Obj_g[n]-= Math.ceil (XX);
- if (Obj_g[n] <) obj_g[n]= "00";//change color, this part is why the yellow movie clips turn red for reasons
- var Rgbs = "0xFF" +obj_g[n]+ "00";//escaped as a string, this Part I do with the stupidest way, really do not understand AS3. Please Master more guidance
- Colorinfo.color = Rgbs;
- M.transform.colortransform = Colorinfo;
- M.Y-= 1-obj_s[n]+.4;//Move Up
- M.x + = obj_fast[n]*obj_action[n]*obj_n[n]*obj_s[n];//for lateral movement
- M.scalex + = (Obj_scal[n])/20 * obj_n[n] * obj_s[n];//scaling horizontally
- M.scaley + = (Obj_scal[n])/20 * obj_n[n] * obj_s[n];//Vertical Scaling
- M.alpha + + 1 *obj_n[n]*obj_s[n];//for transparency settings
- if (M.scalex >= mc_more) {;
- Obj_n[n] = -1;//moving in the opposite direction
- Obj_s[n] =. 2;//Lateral movement speed slows down
- };
- if (M.alpha >= mc_more) {m.alpha = Mc_more;} else if (M.alpha <= math.random () *.1) {Removechildat (m);} If the transparency is higher or lower than the specified value, do the action
- }
- }
- if (i>=maxballs) {i=0;}
- ++i;
- }
- }
- }
Fire.fla file as a scene file, just import the fire.as file
Specific methods:
In the scene attribute, find the document class and enter fire.