开发者

Flex 3: Timer Won't Stop

I'm using Flex 3 with Flash 9.

I'm trying to make a timer that will run once after 1 second. Unfortunately, me timer keeps repeating. How do I get it to stop?

public var myTimer:Timer = new Timer(1000, 1);


private function visFunc():void {

   myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, im开发者_Go百科ageProducer);
   myTimer.start();

}

private function imageProducer(event:TimerEvent):void {


   var img:Image = new Image;
   img.source = image_path;
   img.x = 56;
   img.y = (tf.y + tf.height + 40);
   radioVBox.addChildAt(img, 0);
   this.height = radioVBox.y + radioVBox.height +110;
   myTimer.stop();
   myTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, imageProducer);
}

Thank you.

-Laxmidi


I'd change my code to the following and run some tests, since I don't see any major issues... HOWEVER, if you're not debugging and/or don't have a debugger version of flashplayer running, something may be blowing up on the vbox.addChild line (for example -- null vbox). If your imageProducer function is cool, then your issue is outside of the 'calling' function.

private var myTimer : Timer;

private function visFunc():void
{
    if(myTimer != null) 
    {
        tearDownTimer();
    }

    myTimer = new Timer(1000,1);
    myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, imageProducer);
    myTimer.start();

}

private function tearDownTimer():void
{
    if(myTimer) 
    {
        myTimer.stop();
        myTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, imageProducer);
        myTimer = null;
    }
}


private function imageProducer(event:TimerEvent):void
{
   var img:Image = new Image();
   img.source = image_path;
   img.x = 56;
   img.y = (tf.y + tf.height + 40);
   radioVBox.addChildAt(img, 0);
   this.height = radioVBox.y + radioVBox.height +110;

   tearDownTimer();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜