Skip to main content
July 25, 2013
Answered

Logical function triggered by entering frame is returning #1009 error

  • July 25, 2013
  • 1 reply
  • 1311 views

I have five click boxes on a screen (buttons with a hit area but no image).  If a user clicks a box for the first time, a tick graphic is displayed and a variable is set to True.  If the user clicks the box again the tick disappears and the variable is set to false. 

When the user clicks the Next button the next slide displayed will vary depending on which variables are set to True.

That's all working fine, but if I go forward and then return to my frame, the ticks disappear.  I was trying to create a new function to run as soon as I returned to the frame, check if the variables were set to True or False, and show the appropriate ticks.  It works and there are no errors when I initially run the movie.  But when I click the Next button to leave the frame (frame 5) I get lots of messages like this:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at [filename]::MainTimeline/ticksInBoxes () [
      [filename].MainTimeline::frame5:20]

Here is the relevant code on Frame 5:

addEventListener(Event.ENTER_FRAME, ticksInBoxes);

btnNextS1Start.addEventListener(MouseEvent.CLICK, S1NavForward);

functionticksInBoxes(event:Event):void

{

            if (newtopic == false) {

                        box1Tick.visible = false;
           // the line above this point is frame 5, line 20 mentioned by the output message

            } else {

                        box1Tick.visible = true;

            }

            if (noncom == false) {

                        box2Tick.visible = false;

            } else {

                        box2Tick.visible = true;

            }

            if (changes == false) {

                        box3Tick.visible = false;

            } else {

                        box3Tick.visible = true;

            }

            if (refresher == false) {

                        box4Tick.visible = false;

            } else {

                        box4Tick.visible = true;

            }

            if (badprac == false) {

                        box5Tick.visible = false;

            } else {

                        box5Tick.visible = true;

            }

}

functionTopNew(event:MouseEvent):void

{

            if (newtopic == false) {

                        newtopic = true;

                        box1Tick.visible = true;

            } else {

                        box1Tick.visible = false;

            }

}

functionTopNC(event:MouseEvent):void

{

            if (noncom == false) {

                        noncom = true;

                        box2Tick.visible = true;

            } else {

                        noncom = false;

                        box2Tick.visible = false;

            }

}

functionTopCha(event:MouseEvent):void

{

            if (changes == false) {

                        changes = true;

                        box3Tick.visible = true;

            } else {

                        changes = false;

                        box3Tick.visible = false;

            }

}

functionTopRef(event:MouseEvent):void

{

            if (refresher == false) {

                        refresher = true;

                        box4Tick.visible = true;

            } else {

                        refresher = false;

                        box4Tick.visible = false;

            }

}

functionTopBad(event:MouseEvent):void

{

            if (badprac == false) {

                        badprac = true;

                        box5Tick.visible = true;

            } else {

                        badprac = false;

                        box5Tick.visible = false;

            }

}

function S1NavForward(event:MouseEvent):void

{

            if (newtopic == true) {

                        gotoAndStop(6);

            } else if (noncom == true) {

                        gotoAndStop(7);

            } else if (changes == true) {

                        gotoAndStop(8);

            } else if (refresher == true) {

                        gotoAndStop(9);

            } else if (badprac == true) {

                        gotoAndStop(10);

            } else {

                        trace("Nothing is selected");

            }

}

And here is the code on Frame 6:

btnNextNew.addEventListener(MouseEvent.CLICK, S1NavFromNew);

btnPrevNew.addEventListener(MouseEvent.CLICK, S1NavBackFromNew);

function S1NavFromNew(event:MouseEvent):void

{

            if (noncom == true) {

                        gotoAndStop(7);

            } else if (changes == true) {

                        gotoAndStop(8);

            } else if (refresher == true) {

                        gotoAndStop(9);

            } else if (badprac == true) {

                        gotoAndStop(10);

            } else {

                        gotoAndStop(11);

            }

}

function S1NavBackFromNew(event:MouseEvent):void

{

            gotoAndStop(5);

}

This topic has been closed for replies.
Correct answer

box1Tick doesn't exist when you see that error message.

there are many ways that can happen that cannot be debugged without checking your timeline.  the most common is caused by using box1Tick in a tween.


I've worked it out.

I looked at http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html#ENTER_FRAME which said that "This event has neither a "capture phase" nor a "bubble phase", which means that event listeners must be added directly to any potential targets, whether the target is on the display list or not."

So what I did is change the event listener to say "box1Tick.addEventListener(Event.ENTER_FRAME, ticksInBoxes);".  Adding that reference to one of the tick boxes used in the function was enough to get rid of the error message, even if the way the function ran did not make that specific box visible.

Huzzah!

1 reply

kglad
Community Expert
Community Expert
July 25, 2013

click file>publish settings>swf and tick "permit debugging".  retest.

the line number with the problematic reference will be in the error message.  that line is referencing an object that no longer exists some time when (or after) that code executes.

July 25, 2013

I already turned that on.  That was the third line of the error message in square brackets, and I indicated the relevant line of code with a comment.  I can't work out why I'm being told this line of code is referring to an object that doesn't exist.

kglad
Community Expert
Community Expert
July 25, 2013

box1Tick doesn't exist when you see that error message.

there are many ways that can happen that cannot be debugged without checking your timeline.  the most common is caused by using box1Tick in a tween.