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
Actionscript 3 离开“屏幕”时如何停止计时器_Actionscript 3 - Fatal编程技术网

Actionscript 3 离开“屏幕”时如何停止计时器

Actionscript 3 离开“屏幕”时如何停止计时器,actionscript-3,Actionscript 3,我在一个页面上运行了一些计时器,当我离开该页面时,当该页面正在运行时,我很难确定如何停止 调用来自另一个电影剪辑上的按钮,该按钮正在调用Main.as上的函数。 函数在Main.as中的作用如下: public function goToIntro(){ removeChild(currentScreen); intro = new Intro(); addChildAt(intro,0); cu

我在一个页面上运行了一些计时器,当我离开该页面时,当该页面正在运行时,我很难确定如何停止

调用来自另一个电影剪辑上的按钮,该按钮正在调用Main.as上的函数。

函数在Main.as中的作用如下:

public function goToIntro(){

            removeChild(currentScreen); 
            intro = new Intro();
            addChildAt(intro,0);
            currentScreen = intro;



        }
如果在播放任何带有计时器的场景时单击“介绍”按钮,则会收到此错误消息。信息

不会马上出现,它出现在介绍场景结束并调用下一个场景时

TypeError: Error #1009: Cannot access a property or method of a null object reference.  
    at MethodInfo-202()  
    at flash.utils::Timer/_timerDispatch()  
    at flash.utils::Timer/tick()  
我在介绍页面上有这段代码,当它被删除时,它应该负责清理

public function Intro() {

            addEventListener(Event.REMOVED_FROM_STAGE, removedHandler);


private function removedHandler(event:Event):void {



}
我不知道如何从removedHander函数中删除计时器。我尝试删除事件侦听器,但这会导致其他错误消息。如果侦听器不为null,我尝试进行测试,然后停止它。这显然从未运行过,我使用跟踪语句来测试它。我试着测试计时器是否正在运行,然后停止它,但这也不起作用

救命啊

另外,我对动作脚本和编程完全是新手,所以可以像5岁那样和我说话。谢谢

您可以使用呼叫停止计时器。您可以在removedHandler中进行此调用,如下所示:

private function removedHandler(event:Event):void {
    if (myTimer != null) myTimer.stop();
}

这意味着您必须保留对计时器的引用以停止它。在本例中,引用是myTimer。

我几乎就是这么做的,根据我的跟踪程序,新代码从未运行过。我仍然收到相同的错误消息。你是说永远不会调用removedHandler?简介是要删除的电影剪辑吗?你的问题听起来像是问题发生在你进入介绍时,而不是退出介绍时。您也可以直接在goToIntro函数中停止计时器,而不是侦听从\u阶段删除的\u。removedHandler正在运行,但是If myTimer=空位显然永远不会运行。我正在研究goToIntro的想法,谢谢!当然可以如果我的计时器null未运行,这是因为myTimer未在当前范围内设置。确保在创建计时器时将myTimer设置在适当的位置:myTimer=new Timer10,foo;在currentScreen类中,为removedFromStage添加事件侦听器并停止处理程序中的计时器。