rn2071
03-17-2008, 02:06 PM
Greetings,
I'm new to AS3, so I'm giving myself a pretty big project to learn it. I've been able to figure most things out with the help of Tutorials and useful AS3 tips up until now.
Basically, I've create a movieClip called mcGui that uses the class Gui. Within the movieClip I've created frame labels and places buttons and text at the different frames. There's a label named "title" which resides on the first frame and has the button btnStart. There's a label named "story" that resides on the tenth frame and has the button btnNext.
Now, I call this movieClip from my main timeline with:
var myGui:Gui = new Gui("story");
addChild(myGui);
Here's the Gui.as class:
package com {
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.*;
public class Gui extends MovieClip {
function Gui(lbl:String) {
this.gotoAndStop(lbl);
trace(this.currentFrame);
switch (lbl) {
case "title":
btnStart.addEventListener(MouseEvent.CLICK, fncStart);
break;
case "story":
btnNext.addEventListener(MouseEvent.CLICK, fncNext);
break;
}
}
function fncStart(e:MouseEvent):void {
trace("START");
}
function fncNext(e:MouseEvent):void {
trace("NEXT");
}
}
}
Now, my trace function shows that I am going to frame 10 on my movieClip, however I keep getting this error.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com::Gui()
at test_r1_fla::MainTimeline/frame1()
It don't get this error if I try to go to the "title" frame label. So, it's like the btnNext doesn't exist.
Any ideas? I'm really stuck on this.
I'm new to AS3, so I'm giving myself a pretty big project to learn it. I've been able to figure most things out with the help of Tutorials and useful AS3 tips up until now.
Basically, I've create a movieClip called mcGui that uses the class Gui. Within the movieClip I've created frame labels and places buttons and text at the different frames. There's a label named "title" which resides on the first frame and has the button btnStart. There's a label named "story" that resides on the tenth frame and has the button btnNext.
Now, I call this movieClip from my main timeline with:
var myGui:Gui = new Gui("story");
addChild(myGui);
Here's the Gui.as class:
package com {
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.*;
public class Gui extends MovieClip {
function Gui(lbl:String) {
this.gotoAndStop(lbl);
trace(this.currentFrame);
switch (lbl) {
case "title":
btnStart.addEventListener(MouseEvent.CLICK, fncStart);
break;
case "story":
btnNext.addEventListener(MouseEvent.CLICK, fncNext);
break;
}
}
function fncStart(e:MouseEvent):void {
trace("START");
}
function fncNext(e:MouseEvent):void {
trace("NEXT");
}
}
}
Now, my trace function shows that I am going to frame 10 on my movieClip, however I keep getting this error.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com::Gui()
at test_r1_fla::MainTimeline/frame1()
It don't get this error if I try to go to the "title" frame label. So, it's like the btnNext doesn't exist.
Any ideas? I'm really stuck on this.