package { /** * @author zoe * */ import flash.display.Sprite; import flash.events.TimerEvent; import flash.text.TextField; import flash.utils.Timer; [SWF(width = 750,height = 600)] public class Main extends Sprite { public function Main() { init(); } private var timer:Timer; private function init():void { timer = new Timer(2000,10); timer.addEventListener(TimerEvent.TIMER,timerHandler); timer.start(); } private function timerHandler(event:TimerEvent):void { // trace(timer.currentCount); test(); } private function test():void { var mc:TextField = new TextField(); mc.text = "happy"; mc.width = mc.textWidth +10; mc.height = mc.textHeight+10; mc.x = Math.random()*stage.stageWidth*0.8; mc.y = Math.random()*stage.stageHeight*0.8; addChild(mc); if(timer.currentCount >= 10) { timer.stop(); timer.removeEventListener(TimerEvent.TIMER,timerHandler); } } } }