質問

This is my error when the duck or movie clip hits the screen which it moves from right to left, it will disappear but instead it disappears and show me this error:

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()           

I do not know how to solve this error as I am still new to flash so this is not my Main actionscript but it is my duck actionscript in actionscript 3.0 package {

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);
    }

} }

役に立ちましたか?

解決

After executing this in the last function killDuck:

this.parent.removeChild(this);

The object no longer exist, so if you add an event to the Timer moveDuck, when it is called it tries to move an unexistant MovieClip and crashes.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top