How to remove a hittest?

Hi there,

My animation has a part that carries out a hittest, upon a successful hittest, the animation will proceed via gotoAndPlay(). However, after a successful hit test upon mouse-drop, the following error code pops out continuously in the Output panel and never stops even when the animation has proceeded to the next frame already.

TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at Compilation01_fla::MainTimeline/hitTest()

Apparently, my hittest must have been running still so I’ll need someway to stop the hittest or remove the EventListener upon a successful hittest. Can anyone show me the correct way to code either of the solutions? Also, what does “non-null” mean?

Here’s my code:

[COLOR=RoyalBlue]stop[/COLOR]();

[COLOR=RoyalBlue]var[/COLOR] myBoundaries:[COLOR=RoyalBlue]Rectangle[/COLOR]=[COLOR=RoyalBlue]new Rectangle[/COLOR](431,409,0.1,-15);
//this rectangle is for my targetArea.

MGAswitch.[COLOR=RoyalBlue]addEventListener[/COLOR]([COLOR=RoyalBlue]MouseEvent.MOUSE_DOWN[/COLOR],dragSwitch);
[COLOR=RoyalBlue]function[/COLOR] dragSwitch([COLOR=RoyalBlue]event:MouseEvent[/COLOR]):[COLOR=RoyalBlue]void[/COLOR] {
    MGAswitch[COLOR=RoyalBlue].startDrag[/COLOR]([COLOR=RoyalBlue]false[/COLOR],myBoundaries);
}
//MouseDown starts a mouse drag event.

[COLOR=RoyalBlue]stage[/COLOR].[COLOR=RoyalBlue]addEventListener[/COLOR]([COLOR=RoyalBlue]MouseEvent.MOUSE_UP[/COLOR],dropSwitch2a);
[COLOR=RoyalBlue]function[/COLOR] dropSwitch2a([COLOR=RoyalBlue]event[/COLOR]:[COLOR=RoyalBlue]MouseEvent[/COLOR]):[COLOR=RoyalBlue]void[/COLOR] {
    MGAswitch.[COLOR=RoyalBlue]stopDrag[/COLOR]();
    [COLOR=RoyalBlue]if[/COLOR] ((MGAswitch.[COLOR=RoyalBlue]hitTestObject[/COLOR](targetArea))) {
        [COLOR=RoyalBlue]gotoAndPlay[/COLOR]([COLOR=Green]"slide03"[/COLOR])
        [COLOR=Gray]//trace("listener removed");[/COLOR]
    }
}
//When mouse released, stage listens for a successful hittest and gotoAndPlay() the next segment if successful.

targetArea.[COLOR=RoyalBlue]addEventListener[/COLOR]([COLOR=RoyalBlue]Event.ENTER_FRAME[/COLOR], hitTest);
[COLOR=RoyalBlue]function[/COLOR] hitTest(yourEvent:[COLOR=RoyalBlue]Event[/COLOR]):[COLOR=RoyalBlue]void[/COLOR] {
   [COLOR=RoyalBlue] if [/COLOR]((MGAswitch.[COLOR=RoyalBlue]hitTestObject[/COLOR](targetArea))) {
        //trace("success");
        MGA_on.[COLOR=RoyalBlue]alpha[/COLOR]=1;
    } [COLOR=RoyalBlue]else[/COLOR] {
        //trace("fail");
        MGA_on.[COLOR=RoyalBlue]alpha[/COLOR]=0;
    }
}
//When my switch is in the on-position, a screen will turn on; if in the off position, screen turns off.

Thanks in advance for helping!!