Error #1009: When eventlistener is other than frame 1
So, what I'm trying to do is build a simple page where from the first page with buttons. You click a button and it fires off a simple gotoandstop function like this:
stop();
l2v2_btn.addEventListener(MouseEvent.CLICK, l2v2);
function l2v2(event:MouseEvent):void
{
gotoAndStop(2);
}
From there I want each page to have a bunch of buttons, each button has a sound that plays when you hit it. Wonder, works, easy, swell.
The problem arises when I try to attach a function to those buttons. I want each button press to add a child, or remove a child. Now...when I just do it all on frame 1 - no problem, but when I go from frame 1 (main menu to any other frame (at this point frame 2) I get this, an error that I'm so sick of I can puke.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at shit_fla::MainTimeline/frame2()
at flash.display::MovieClip/gotoAndStop()
at shit_fla::MainTimeline/l2v2()
actions on frame 1 are printed above
code on frame 2 ate here:
var nd:And = new And();
var big:Big = new Big();
var current = "none";
and_btn.addEventListener(MouseEvent.CLICK, fAnd);
big_btn.addEventListener(MouseEvent.CLICK, fBig);
function fBig(event:MouseEvent):void
{
if(current == "none")
{
addChild(nd);
current = nd.name;
}
else if(current != "none")
{
removeChild(getChildByName(current));
addChild(nd);
nd.x = 818;
nd.y = 438;
current = nd.name;
}
}
function fAnd(event:MouseEvent):void
{
if(current == "none")
{
addChild(big);
current = big.name;
}
else if(current != "none")
{
removeChild(getChildByName(current));
addChild(big);
current = big.name;
}
}
Basically I just want a main page, I click a button takes me to another page with buttons, each button plays a vocabulary audio and adds a sprite (vocab word to the stage) when
It works when I'm on frame one, the swapping out the sprites, but when I try to go another frame with the same it get the aforementioned error. I know this is a simple fix, could someone please help? This is driving me bonkers
