Actionscript 3 制作adobe flash cs6游戏时,我的动作脚本3.0出错
这是我的错误,当鸭子或电影剪辑击中它从右向左移动的屏幕时,它将消失,但它会消失,并显示此错误:Actionscript 3 制作adobe flash cs6游戏时,我的动作脚本3.0出错,actionscript-3,actionscript,adobe,typeerror,Actionscript 3,Actionscript,Adobe,Typeerror,这是我的错误,当鸭子或电影剪辑击中它从右向左移动的屏幕时,它将消失,但它会消失,并显示此错误: 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() 我不知
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,而是actionscript 3.0中的duck 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);
}
导入flash.display.MovieClip;
导入flash.utils.Timer;
导入flash.events.TimerEvent;
导入flash.events.MouseEvent;
公共类电影{
var moveDuck:定时器=新定时器(10);
var speedX:数字;
公共职能(){
this.addEventListener(MouseEvent.CLICK,KillDuck);
moveDuck.addEventListener(TimerEvent.TIMER,ducksmove);
moveDuck.start();
speedX=10;
}
函数ducksmove(evt:TimerEvent):无效
{
这个.x-=speedX;
如果(this.x在最后一个函数中执行此操作后:
this.parent.removeChild(this);
该对象不再存在,因此如果向计时器moveDuck添加事件,当调用该事件时,它会尝试移动一个不存在的MovieClip并崩溃