这是我的错误,当鸭子或电影剪辑击中它从右向左移动的屏幕时,它会消失,但它会消失,并向我显示这个错误:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Duck/ducksmove()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick() 我不知道如何解决这个错误,因为我对flash还不熟悉,所以这不是我的主要actionscript,但它是我在ActionScript3.0包中的鸭子actionscript。
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
public class Duck extends MovieClip {
var moveDuck:Timer = new Timer(10);
var speedX:Number;
public function Duck() {
this.addEventListener(MouseEvent.CLICK,KillDuck);
moveDuck.addEventListener(TimerEvent.TIMER,ducksmove);
moveDuck.start();
speedX = 10;
}
function ducksmove(evt:TimerEvent):void
{
this.x -= speedX;
if (this.x <=0)
{
moveDuck.stop();
moveDuck.removeEventListener(TimerEvent.TIMER,ducksmove);
this.parent.removeChild(this);
}
}
function KillDuck(evt:MouseEvent):void
{
var p:MovieClip = this.parent as MovieClip;
p.setScore();
p.updatecount();
this.removeEventListener(MouseEvent.CLICK,KillDuck);
this.parent.removeChild(this);
moveDuck.addEventListener(TimerEvent.TIMER,ducksmove);
}}}
发布于 2014-05-12 06:44:48
在最后一个函数killDuck中执行此操作之后:
this.parent.removeChild(this);
该对象不再存在,因此如果将一个事件添加到计时器moveDuck中,那么当它被调用时,它会尝试移动一个不存在的MovieClip并崩溃。
https://stackoverflow.com/questions/23589747
复制相似问题