Forked from: ton_'s removeEventListenerの練習 diff:28 TimerEventの練習 ton_ forked:0favorite:0lines:78license : MIT License modified : 2010-10-26 15:39:26 Embed Tweet package { import flash.utils.Timer; import flash.display.Sprite; import flash.display.Bitmap; import flash.events.Event; import flash.events.MouseEvent; import flash.events.TimerEvent; import flash.geom.Matrix; import frocessing.core.F5BitmapData2D; [SWF(wisth=465,height=465,backgroundColor=0x222222,flameRate = 30)] public class F5B2D extends Sprite { private var fb:F5BitmapData2D; private var b1:Sprite; private var b2:Sprite; private var tim1:Timer; //メインファンクション public function F5B2D() { graphics.lineStyle(1,0xffffff); graphics.drawRect(48,29,366,262); DrawMode(); timer(); button(); Add(); } //F5BitmapData2Dの描画設定 public function DrawMode():void{ fb = new F5BitmapData2D( 364, 260, false, 0 ); fb.blendMode = "add"; fb.colorMode( "rgb", 364,1,260,255); var bit:Bitmap = new Bitmap(fb.bitmapData); bit.x=49; bit.y=30; addChild(bit); } public function timer():void{ tim1 = new Timer(33,20); } //ボタンの生成 public function button():void{ b1 = new Sprite(); b1.graphics.lineStyle(3,0xff0000); b1.graphics.beginFill(0xcc0000); b1.graphics.drawRoundRect(400,390,60,40,5,5); b1.graphics.endFill(); b1.buttonMode = true; addChild(b1); b2 = new Sprite(); b2.graphics.lineStyle(3,0x0000ff); b2.graphics.beginFill(0x0000cc); b2.graphics.drawRoundRect(330,390,60,40,5,5); b2.graphics.endFill(); b2.buttonMode = true; addChild(b2); } //イベントリスナー登録 public function Add():void{ b1.addEventListener(MouseEvent.MOUSE_DOWN,start); b2.addEventListener(MouseEvent.MOUSE_DOWN,clear); } //enter_frame public function start(e:Event):void{ tim1.reset(); tim1.addEventListener(TimerEvent.TIMER, Draw); tim1.start(); } //ランダムな円の生成 public function Draw(e:Event):void{ fb.beginDraw(); var cx:int = Math.random()*364; var cy:int = Math.random()*260; fb.fill(cx,1,cy,Math.random()*85); fb.noStroke(); fb.circle(cx,cy,Math.random()*40); fb.endDraw(); } //描画領域のクリア public function clear(e:MouseEvent):void{ fb.blendMode="normal"; fb.fill(0); fb.beginDraw(); fb.rect(0,0,364,260); fb.endDraw(); } } } Code Fullscreen Preview Fullscreen TIMER TimerEvent blendMode start addEventListener bitmapData Bitmap Timer reset TimerEvent.TIMER Math.random int