The effect is as follows
The first is the source code, saved as a main.as file, and associated with the FLA to run.
The code is as follows |
Copy Code |
Package { Import flash.display.*; Import flash.events.*; Import flash.text.*; Import Flash.utils.Timer; Import Flash.geom.Matrix; [SWF (width=800, HEIGHT=465,BACKGROUNDCOLOR=0XFFFFFF, framerate=24)] public class Main extends Sprite { private Var pointnum:number=0; private var Ptxt:textfield = AddChild (New TextField ()) as TextField; private var Matrix:matrix = new Matrix (); Public Function main () { var t:timer = new Timer (500); var tfun=function () {Matrix.creategradientbox (800,465,math.pi/2,0,0), Graphics.begingradientfill ( Gradienttype.linear,[0x00ccff,0xffffff],[0.3,1],[0,255],matrix), Graphics.drawrect (0,0,800,465), T.addeventlistener (Timerevent.timer,function (e) {var mc; var mcfun = function () {Mc=addchild (New Balloon (Math.random () *10 + 1)), Mc.x=math.round (Math.random () * (700-30)) +30, Mc.y=465}.apply (); Mc.addeventlistener (Mouseevent.mouse_down, function (e) {removechild (e.target.parent), ptxt.htmltext= ' <font size = "color=" #ff0000 ">score: ' + (++pointnum). toString () + ' </font> '}), T.start ()}.apply (); } } } Import Flash.display.Sprite; Import flash.events.Event; Class Balloon extends sprite{ private Var Speed:number; private var s:sprite =addchild (New Sprite ()) as Sprite; Public Function Balloon (_t) { var sfun=function () {s.graphics.linestyle (1, 0), S.graphics.curveto ( -10, 0,), S.graphics.beginfill (Math.random ( ) * 0XFFFFFF + 0xff000000), s.graphics.drawcircle (0,0,20), Speed=math.round (_t)}.apply (); S.addeventlistener (Event.enter_frame,function (e) {s.y-= speed;}); } } |
This code, with a line, with a semicolon, the statement of a line, I do not have a line to write n sentence of the smart.
This code, some places are not standardized, such as the use of anonymous functions, but not to optimize efficiency (object pool), but as a complete game, it can run up, remove import those, the core code is 20 lines.
Although only a short line of 30 lines of code, but we use the class of knowledge, objects, gradients, matrices, event processing, anonymous functions, random operations, as well as graphic graphics, such as though small spite wow