每20秒调用一次Flash AS3功能

Den*_*one 1 flash function increment actionscript-3

如何在AS3 Flash中设置增量功能.我正在尝试在我的视频启动时启动递增功能,然后每20秒运行相同的功能,直到视频停止.

就像是:

    my_player.addEventListener(VideoEvent.COMPLETE, completePlay);
    my_player.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, startPlay);

   function startPlay(){
       startInc();
       //OTHER items are started and set within this function that do not have to do with the incremented function.
    }


   function completePlay(){
       //This is where the startInc is stopped but not removed since it will be used again.

    }


     function startInc(){
          //This function should run every 20 seconds.
     }
Run Code Online (Sandbox Code Playgroud)

Jas*_*ges 5

在玩家的VideoEvents周围使用计时器.

package
{
    import flash.display.Sprite;
    import flash.events.TimerEvent;
    import flash.events.VideoEvent;
    import flash.utils.Timer;

    public class IncrementTimer extends Sprite
    {

        private var my_player:*;

        private var timer:Timer;

        public function IncrementTimer()
        {
            my_player.addEventListener(VideoEvent.COMPLETE, completePlay);
            my_player.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, startPlay);
        }

        protected function startPlay(event:VideoEvent)
        {
            timer = new Timer(20000);
            timer.addEventListener(TimerEvent.TIMER, startInc);
            timer.start();
        }

        protected function completePlay(event:VideoEvent)
        {
            timer.reset();
        }

        protected function startInc(event:TimerEvent)
        {
            // called every 20-seconds
        }

    }
}
Run Code Online (Sandbox Code Playgroud)