Catch 22....wrong number of arguments or cannot reference null object
I am having trouble creating arrow buttons to move from one frame to the next in my fla file. In addition to my page forward/page backward buttons, I also have a table of contents off to the side. I would like to create a function that will control the buttons at the beginning, and refer to them in subsequent frames so that the forward and back buttons will work even when that frame is jumped to. I am experiencing an expected number of arguments error when I use the code without referencing a null value...however, when I try to set the function to null, I get an error that states that I cannot reference a method or object with a null reference....can anyone tell me where to go to fix this problem?
Code:
function arrows(e:MouseEvent=null):void {
nextArrow.addEventListener(MouseEvent.CLICK, nextArrowAdvance);
nextArrow.buttonMode = true;
function nextArrowAdvance(e:Event):void {
nextFrame();
}
prevArrow.addEventListener(MouseEvent.CLICK, prevArrowBack);
prevArrow.buttonMode = true;
function prevArrowBack(e:Event):void {
prevFrame();
}
}
Your explanation makes no sense. Seriously. I have no idea what you mean by "set the function to null".
First thing's first. Get those nested functions out of the arrows function. There's no reason for them to be nested.
Then, post each code version you've tried and associated full error messages. Is the code above the one giving the null error or the one giving the unexpected number of arguments error?
When are you calling the arrows function? What are you passing to it?
This may all be in the fla you posted, but not all of us have flash to open it.
This should be sufficient, on the first frame:
Code:
nextArrow.addEventListener(MouseEvent.CLICK, nextArrowAdvance);
nextArrow.buttonMode = true;
function nextArrowAdvance(e:Event):void {
nextFrame();
}
prevArrow.addEventListener(MouseEvent.CLICK, prevArrowBack);
prevArrow.buttonMode = true;
function prevArrowBack(e:Event):void {
prevFrame();
}
That is, there should be no reason you need an arrows function if you want the buttons set up from the beginning.
Am I right in thinking that if you click on the next arrow then it will go to the next frame (and/or section)? If so; can't you just do the following?
Actionscript Code:
// create a variable for what section you're on var section:Number;
// listeners for the arrows nextArrow.addEventListener(MouseEvent.CLICK, nextSection); prevArrow.addEventListener(MouseEvent.CLICK, prevSection);
// if the next arrow is pressed then if it's not on the last section then // it will jump to next frame function nextSection(e:MouseEvent):void{ if(section =<4){ section = section + 1; gotoAndStop(nextFrame); } }
// and if the previous arrow is pressed then if it's not on the first // section then it jump to previous frame function prevSection(e:MouseEvent):void{ if(section =>1){ section = section - 1; gotoAndStop(prevFrame); } }
// you'll also have to go in your other functions and set the section variable // in each onein case the user uses the menu instead of the arrows like: function courseIntroAdvance(e:Event):void{ gotoAndPlay(2); section = 1; }
function courseObjectivesAdvance(e:Event):void{ gotoAndPlay(3); section = 2; }