Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Logical function triggered by entering frame is returning #1009 error

Guest
Jul 24, 2013 Jul 24, 2013

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);

}

TOPICS
ActionScript
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Jul 28, 2013 Jul 28, 2013

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

...
Translate
Community Expert ,
Jul 24, 2013 Jul 24, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 25, 2013 Jul 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 25, 2013 Jul 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 28, 2013 Jul 28, 2013

I've worked it out.

I looked at http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html#ENTER_FRA... 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 28, 2013 Jul 28, 2013

it doesn't look like you should be using an enterframe loop there.  further, if you do need that loop, you should be removing it when it no longer needs to run.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 28, 2013 Jul 28, 2013

I see what you mean.  I didn't realise Enter_Frame ran on every frame.  I was looking for something that would trigger when I got to that specific frame.

I tried turning the Enter_frame function off again, but I'm struggling to get it to work right when I use the same type of trigger more than once.

Is there another trigger I can use instead?  Something that says "when Frame 5 is loaded, go find this function".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 28, 2013 Jul 28, 2013

you would use:

ticksInBoxes(null);

btnNextS1Start.addEventListener(MouseEvent.CLICK, S1NavForward);

functionticksInBoxes(event:Event):void

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 29, 2013 Jul 29, 2013
LATEST

Splendiferous.  That was exactly what I needed.  Thank you for your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines