1 Reply Latest reply on May 29, 2015 4:49 AM by Ned Murphy

    Error when catching objects, scoring and lives count, please help?


      Hi, I'm currently making a catching game. So the user have to catch the right letter to get a score and go to the next question.

      The letters are movieclips and I made the falling animation with motion tween.

      I converted the avatar to a movieclip too.

      When the avatar hits the right letter, the user will get 100 points and when the avatar hits the wrong letter, there will be a pop up button that says "try again" and it will lost its lives by 1.

      Here's my code:



      import flash.events.KeyboardEvent;

      stage.addEventListener(KeyboardEvent.KEY_DOWN, moveavatar);

      avatarmove.addEventListener(Event.ENTER_FRAME, handleCollision);


      trybutton.visible = false;

      var myscore = 0; 

      var mylives = 5;

      score.text = myscore+"";

      lives.text = mylives+"";


      //Move avatar function

      function moveavatar (event:KeyboardEvent):void


        avatarmove.x = Math.max(0,Math.min(stage.stageWidth-avatarmove.width,avatarmove.x - int(event.keyCode==37) * 10 + int(event.keyCode==39) * 10));



      //Collision between the avatar and the letters

      function handleCollision(e:Event):void





          a_alphabet.visible = false;



        else if(avatarmove.hitTestObject(o_alphabet))



          o_alphabet.visible = false;

          trybutton.visible = true;




      //try again button

      trybutton.addEventListener (MouseEvent.CLICK, ayo1);

      function ayo1(event:MouseEvent):void{

        o_alphabet.visible = true;

        trybutton.visible = false;




      var myTimer:Timer = new Timer(1000);

      myTimer.addEventListener(TimerEvent.TIMER, countdownHandler);

      function  countdownHandler(event:TimerEvent):void{

        countdown.text = 30-myTimer.currentCount+" s remaining";







      I keep getting this error when the avatar hits the letter:

        TypeError: Error #2007: Parameter hitTestObject must be non-null.

        at flash.display::DisplayObject/_hitTest()

        at flash.display::DisplayObject/hitTestObject()

        at gamecompletethewords_fla::MainTimeline/handleCollision()


      And this error on the next frame:

                TypeError: Error #1009: Cannot access a property or method of a null object reference.

                at gamecompletethewords_fla::MainTimeline/handleCollision2()


      And the the lives won't decrease when the avatar hits the wrong letter, but when I move to the next frame it will decrease by -27. It's just really weird.

      Can someone help me with these problems? I'm totally new to this and I have no idea how to fix it