在我的Flash游戏的一些级别MovieClip中,有一个MovieClip可以控制我创建的自定义相机。相机和MovieClip都能正常顺畅地运行。但是,无论何时完成某个级别并从游戏中移除,我都会Error #1009
无法识别checkCameraZoom
功能。此外,此MovieClip不会动态添加代码,而是在运行时之前放置在库中指定级别的MovieClip中。有没有办法解决这个错误?
ZoomOutArea类:
package com.engine.assetHolders
{
import com.engine.documentClass.*;
import flash.display.*;
import flash.events.*;
public class ZoomOutArea extends MovieClip
{
public function ZoomOutArea():void
{
this.visible = false;
this.addEventListener(Event.ADDED_TO_STAGE, initZoomOutArea);
// constructor code
}
public function initZoomOutArea(event:Event):void
{
this.addEventListener(Event.ENTER_FRAME, checkCameraZoom);
}
public function checkCameraZoom(event:Event):void
{
if (Document.getInstance != null)
{
if (this.hitTestObject(MovieClip(parent.parent).player.playerHitArea))
{
this.hitTestZoom(0.6);
}
if (! this.hitTestObject(MovieClip(parent.parent).player.playerHitArea))
{
this.hitTestZoom(1);
}
}
}
public function hitTestZoom(zoomLevel):Number
{
MovieClip(parent.parent).cameraScale = zoomLevel;
return zoomLevel;
}
}
}
答案 0 :(得分:1)
当您将ENTER_FRAME
事件添加到舞台时,您会注册该类,但您永远不会注销它。这就是为什么它在从舞台上移除后仍然继续进行,并且不再有parent
。
您可以为Event.REMOVED_FROM_STAGE
添加另一个侦听器,然后删除checkCameraZoom
侦听器:
public function initZoomOutArea(event:Event):void
{
this.addEventListener(Event.ENTER_FRAME, checkCameraZoom);
this.addEventListener(Event.REMOVED_FROM_STAGE, onRemoved);
}
private function onRemoved(event:Event):void
{
this.removeEventListener(Event.ENTER_FRAME, checkCameraZoom);
}