4 Replies Latest reply on Nov 15, 2012 2:56 PM by Ned Murphy

    Flash Error #1009 --> NEED HELP!

    FLasHADdiCt97

      Okay.  I am relatively new to AS3 and I have been working on creating a visual timer.  My code is very simple, and I can't figure out why Flash Pro CS6  is giving this error message in the Output:

       

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

                at TMR_fla::MainTimeline/timer1hit()

       

       

      My code looks exactly like the following:

       

      import flash.events.Event;

       

       

      stop();

       

       

      function timer1move():void {

                timer1.x-= 8;

      }

      var MyInterval1:uint = setInterval(timer1move, 50);

       

       

      timer1.addEventListener(Event.ENTER_FRAME, timer1hit);

      function timer1hit(e:Event) {

                if(timer1.hitTestObject(finish1)) {

                          gotoAndStop(2);

                          clearInterval(MyInterval1);

                }

       

      }

       

       

      I cannot figure out why FLash is giving me this error.  Mainly because my code works great!  It does exactly what I told it to do, it goes to Frame 2 and stops.  But in the Output the error message just keeps repeating forever.  I have looked all over this forum and found multiple topics on this problem but none of them help.  Few extra key notes:

       

      1.  My second frame has absolutely ZERO code.  Just some scribbles on stage to indicate that I've made it to the 2nd Frame.

      2.  My stage for frame 1 looks like this:

       

      Flash Error #1009.png

      The object on the right is my timer.  The rectangle on the left is my finish.

       

      Rectangle has an instance name of finish1

      Timer has an instance name of timer1

       

      I have triple checked the instance names, I know that they are all spelled right.  Can somone help me? 

        • 1. Re: Flash Error #1009 --> NEED HELP!
          Ned Murphy Adobe Community Professional & MVP

          The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....

           

          - is declared but not instantiated

          - doesn't have an instance name (or the instance name is mispelled)

          - does not exist in the frame where that code is trying to talk to it

          - is animated into place but is not assigned instance names in every keyframe for it

          - is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).

           

          If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.

          • 2. Re: Flash Error #1009 --> NEED HELP!
            Ned Murphy Adobe Community Professional & MVP

            If the error is repeating forever, it is probably because you have tha ENTER_FRAME listener continuing on.  If you are in frame 2 and any of the objects that the ENTER_FRAME event handler function is targeting are only in frame 1, then that will be the source of the error.  In your event handler you should remove that listener before you change frames.

             

            timer1.addEventListener(Event.ENTER_FRAME, timer1hit);

            function timer1hit(e:Event) {

                      if(timer1.hitTestObject(finish1)) {

                                timer1.removeEventListener(Event.ENTER_FRAME, timer1hit);

                                clearInterval(MyInterval1);

                                gotoAndStop(2);

                     }

             

            }

            • 3. Re: Flash Error #1009 --> NEED HELP!
              FLasHADdiCt97 Level 1

              The problem was that my  removeEventListener was listed after my gotoAndStop(2);

               

              You fixed my problem! Thx! 

              • 4. Re: Flash Error #1009 --> NEED HELP!
                Ned Murphy Adobe Community Professional & MVP

                You're welcome