As 3.0 effect of fire

Source: Internet
Author: User
Tags addchild arrays
  1. Package {
  2. Import Flash. Geom. matrix;//Color Gradient Class library pour
  3. The import Flash.display.sprite;//sprite class is a basic display list building block
  4. The Import Flash.display.gradienttype;//graphics class contains a set of methods that you can use to create vector shapes
  5. public class Mack_fire extends Sprite {//This class is the Spark prototype class
  6. private Var Fire:sprite;
  7. var Mymatrix:matrix;
  8. Public Function Mack_fire () {
  9. Fire = new Sprite ();//Initialize a movie clip
  10. Mymatrix = new Matrix ()//need to use the flash with the class, where the role is to make spark particles color gradient effect
  11. var boxwidth:int = 16;//Spark particle color gradient width high setting, below is height
  12. var boxheight:int = 16;
  13. var boxrotation:uint = variable used by math.pi/2;//color gradient
  14. var tx:int = Preliminary coordinates of 0;//movie clips
  15. var ty:int = 0;
  16. Mymatrix.creategradientbox (Boxwidth, Boxheight, Boxrotation, TX, ty);//below starts with the color Pay Value section, please refer to the specific usage of Creategradientbox
  17. var type:string = gradienttype.radial;
  18. var mycolors:array = [0xffff00, 0xffff00];//color gradient, white to white
  19. var myalphas:array = [1, 0];//transparency from, transparent to opaque
  20. var myralphas:array = [0, 255];
  21. var spreadmethod:string = "pad";
  22. var interp:string = "RGB";
  23. var focalptratio:number = 0;
  24. Fire.graphics.beginGradientFill (Type, Mycolors,myalphas,myralphas, Mymatrix, Spreadmethod, Interp, Focalptratio); Here please refer to the manual for Begingradientfill to understand
  25. Fire.graphics.drawCircle (8, 8, 8);//Make a circle, radius and center point coordinates, can refer to Drawcircle
  26. AddChild (fire);
  27. }
  28. }
  29. }

Fire.as:

  1. /***************ant qq:305033389******************/
  2. /************* Please support original, please open source code ****************/
  3. /********** please let more as enthusiasts have information to learn *************/
  4. /******** This work is my study work, not perfect works ***********/
  5. Package {
  6. Import Flash.display.MovieClip;
  7. Import Flash.events.EventDispatcher;
  8. Import flash.events.Event;
  9. Import Flash.display.BlendMode;
  10. Import Flash.filters.GlowFilter;
  11. Import Flash.geom.ColorTransform;
  12. public class Fire extends MovieClip {
  13. private Var Fires:mack_fire;
  14. Private Const MAXBALLS:INT = 60;//Spark Quantity
  15. Private Const MC_X:INT = stage.stageheight/2;//start of Fire x coordinates
  16. Private Const MC_Y:INT = stage.stageheight/2;//+stage.stageheight/4;//start of fire y-coordinate
  17. 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
  18. Private Const MCY:INT = 1;//Move Up speed
  19. Private var i=1;//count variable
  20. private var obj_scal:array=new array ();//zoom variable Save arrays
  21. private var obj_fast:array=new array ();//move speed variable save arrays
  22. private var obj_action:array=new Array ();//horizontal Move Speed change variable
  23. private var obj_n:array=new Array ();//lateral Movement Direction control variable
  24. private var obj_s:array=new Array ();//transverse velocity control variable
  25. private var obj_gs:array=new Array ();
  26. private var obj_g:array=new Array ();//Color control variable
  27. Public Function Fire () {
  28. AddEventListener (EVENT.ENTER_FRAME,FIRE_MV);
  29. }
  30. Public Function FIRE_MV (event:event): void{
  31. var k = Math.random ()//Create the number, this variable determines the distance of the spark, has moved the range
  32. var scale:number = k? k:1;//creates a random number, which is less than 1, more than 0.
  33. fires = new Mack_fire ();
  34. Fires.scalex = Fires.scaley = Fires.alpha = scale;//component Scaling and transparency settings, based on the number of seconds above
  35. Obj_g[i] = 100;
  36. Obj_gs[i] = (1-scale+.2) *3;//defines a new array element, changing the color of the component
  37. Obj_fast[i] = Math.floor (scale*2);//longitudinal moving speed main variable
  38. Obj_action[i]= (Math.random () >0.5)? 1:-1;//longitudinal moving direction main variable
  39. Obj_scal[i] = 1-obj_fast[i]/10;//controls the scaling of the in-process spark
  40. Obj_n[i] = obj_s[i] = 1;
  41. fires.x= mc_x;//defines the horizontal axis generated by the spark
  42. Fires.y= mc_y;//defines the ordinate that sparks produce
  43. 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
  44. 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.
  45. AddChild (fires);
  46. for (var n:int = 1; n<maxballs; ++n) {
  47. var m=getchildbyname ("Fire" +n);//Use the Spark movie clip defined above
  48. if (m) {
  49. var colorinfo:colortransform = m.transform.colortransform;//Define color controller
  50. var xx=obj_gs[n]*2;
  51. Obj_g[n]-= Math.ceil (XX);
  52. if (Obj_g[n] <) obj_g[n]= "00";//change color, this part is why the yellow movie clips turn red for reasons
  53. 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
  54. Colorinfo.color = Rgbs;
  55. M.transform.colortransform = Colorinfo;
  56. M.Y-= 1-obj_s[n]+.4;//Move Up
  57. M.x + = obj_fast[n]*obj_action[n]*obj_n[n]*obj_s[n];//for lateral movement
  58. M.scalex + = (Obj_scal[n])/20 * obj_n[n] * obj_s[n];//scaling horizontally
  59. M.scaley + = (Obj_scal[n])/20 * obj_n[n] * obj_s[n];//Vertical Scaling
  60. M.alpha + + 1 *obj_n[n]*obj_s[n];//for transparency settings
  61. if (M.scalex >= mc_more) {;
  62. Obj_n[n] = -1;//moving in the opposite direction
  63. Obj_s[n] =. 2;//Lateral movement speed slows down
  64. };
  65. 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
  66. }
  67. }
  68. if (i>=maxballs) {i=0;}
  69. ++i;
  70. }
  71. }
  72. }

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.