Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
每20秒调用一次Flash AS3功能_Flash_Actionscript 3_Function_Increment - Fatal编程技术网

每20秒调用一次Flash AS3功能

每20秒调用一次Flash AS3功能,flash,actionscript-3,function,increment,Flash,Actionscript 3,Function,Increment,如何在AS3闪存中设置增量函数。我尝试在视频开始时启动递增函数,然后每20秒运行一次相同的函数,直到视频停止 比如: my_player.addEventListener(VideoEvent.COMPLETE, completePlay); my_player.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, startPlay); function startPlay(){ startInc();

如何在AS3闪存中设置增量函数。我尝试在视频开始时启动递增函数,然后每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.
     }

在播放器的视频事件周围使用计时器

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
        }

    }
}

在播放器的视频事件周围使用计时器

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
        }

    }
}

谢谢,我在发帖2分钟后发现了计时器类+1和检查!我喜欢使用“timer.reset()”而不是“stop”,谢谢我在发布2分钟后发现了timer类+1和检查!我喜欢使用“timer.reset()”而不是“stop”我的道歉,我以为这已被删除,但我可以看到它仍然存在于flash.utils包中。不过,相关文档确实建议使用计时器。这种方法有什么好处吗?很简单,就是这样。我猜他们两个在内部都做同样的事情。这比创建计时器、添加事件侦听器以及所有这些都要容易。很抱歉,我以为这已经被删除了,但我可以看到它仍然存在于flash.utils包中。不过,相关文档确实建议使用计时器。这种方法有什么好处吗?很简单,就是这样。我猜他们两个在内部都做同样的事情。比创建计时器、添加事件侦听器等更容易