user2051003
user2051003

Reputation: 3

Error #2007: Parameter hitTestObject must be non-null

this is my code- it's working and moving to frame 3 but everything is stuck there and I get this Error #2007

function createMC(event:Event):void 
{
  var hasa_mc:MovieClip= new hasa();
  stage.addChild(hasa_mc);
  var halfMc:int=hasa_mc.width/2;
  hasa_mc.x=randomNum(70+halfMc,480-halfMc);
  hasa_mc.addEventListener(Event.ENTER_FRAME, abc);
  hasa_mc.addEventListener(Event.ENTER_FRAME, dropCheckHit);

  function dropCheckHit(event:Event):void 
  {
    if (hasa_mc.hitTestObject(hauta1_mc)) {
        hasa_mc.removeEventListener(Event.ENTER_FRAME, dropCheckHit);
        event.target.parent.removeChild(event.target);
        countertime++;
        score_txt.text=String(countertime*10)


        if (countertime==10)
        {
    gotoAndStop(3);

    }

Upvotes: 0

Views: 2268

Answers (2)

user2051003
user2051003

Reputation: 3

thank you. from where i need to remove also ? still does not works. when it goes to frame 3 there is new MC that hit new object

function dropCheckHit(event:Event):void {

    if (hasa_mc.hitTestObject(hauta1_mc)) {
        hasa_mc.removeEventListener(Event.ENTER_FRAME, dropCheckHit);
        event.target.parent.removeChild(event.target);
        countertime++;
        score_txt.text=String(countertime*10)


        if (countertime==10)
        {

     gotoAndStop(3);
     hasa_mc.removeEventListener(Event.ENTER_FRAME, dropCheckHit);

    }



        hauta1_mc.nextFrame();}

          else if (hasa_mc.y > 380) 
{
    xdirection = 0;
    ydirection = 0;
    hasa_mc.x = 190;

    hasa_mc.y = 200;
    hauta1_mc.x=220;


    lifeCounter--; // 
    life_txt.text=String(lifeCounter);
    trace(lifeCounter);
    if (lifeCounter==0)
    {
    gotoAndStop(5);
    }
}

}

}

Upvotes: 0

Simon McArdle
Simon McArdle

Reputation: 893

The error code and description refers to the line:

if (hasa_mc.hitTestObject(hauta1_mc)) {

My guess would be the movieclip hauta1_mc does not exist on frame 3 of your movie, so once you go to frame 3 and your dropCheckHit function executes the null reference error is thrown.

To resolve you can remove the enter frame listener and stop checking if the movieclip has been hit:

if (countertime==10)
{
  hasa_mc.removeEventListener(Event.ENTER_FRAME, dropCheckHit);
  gotoAndStop(3);
}

Note: You may need to remove the other listener you have on hasa_mc as well if hasa_mc does not exist in frame 3.

Upvotes: 1

Related Questions