【发布时间】:2015-03-19 16:20:29
【问题描述】:
我正在尝试使用 Flash 制作类似于马里奥的游戏。我有一个名为 Enemy.as 的外部文件。在这个文件中,我想获取杀死的敌人数量并将其显示在文本框中(在舞台上)。但我面临 #1009 错误。
这是我的代码:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.text.TextField;
public class Enemy extends MovieClip
{
var player:MovieClip;
public var enemyKilled:int;
public function Enemy(xLocation:int, yLocation:int)
{
// constructor code
x = xLocation;
y = yLocation;
addEventListener(Event.ENTER_FRAME, Enemyloop);
}
public function Enemyloop(e:Event):void
{
/*//the looping code goes here
player = MovieClip(root).player;
if(this.hitTestObject(player))
{
this.removeEventListener(Event.ENTER_FRAME,Enemyloop);
parent.removeChild(this);
}*/
}
public function removeSelf():void
{
trace("remove self");
removeEventListener(Event.ENTER_FRAME, Enemyloop); //stop the loop
this.parent.removeChild(this); //tell this object's "parent object" to remove this object
enemyKilled++;
MovieClip(root).tbxEnemy.text = ("enemyKilled: " + enemyKilled.toString());
}
}
}
[这是错误信息:
删除自己
TypeError:错误 #1009:无法访问空对象引用的属性或方法。 在敌人/removeSelf() 在 Ass3_fla::MainTimeline/loop() view image
【问题讨论】:
标签: actionscript-3 flash