Logical function triggered by entering frame is returning #1009 error
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);
}
