【发布时间】:2011-08-31 20:55:49
【问题描述】:
假设我们在 Flash 库中有一个动画剪辑“Enemy”,并且与它相关联的类“Enemy.as”监听 ENTER_FRAME 事件,如下所示,
public function Enemy():void
{
//constructor of this "Enemy.as" class
addEventListener(Event.ENTER_FRAME, move);
}
private function move(evt:Event):void
{
x += 5;
}
现在我的问题是,如果这个“Enemy.as”在其他类中被实例化,说“Main.as”再次在同一个实例化的 Enemy 对象上使用 ENTER_FRAME 事件,如下所示,
public function Main():void
{
//constructor of this "Main.as" class
enemy1 = new Enemy();
enemy1.addEventListener(Event.ENTER_FRAME, checkCollision);
}
private function checkCollision(evt:Event):void
{
if(enemy1.x == mainObj.x)
{
//do something
}
}
这是优化方面的好方法吗?或者根本不应该使用这种方法?
【问题讨论】:
标签: actionscript-3 events event-handling