Hello,
I was average at AS2 and now I’m moving on to AS3. I’ve just read the tutorials on here regarding Classes to get myself clued up, and it all makes a fair bit of sense.
I’m attempting to make my first Flash that uses an external .as file. However, I can’t see why I’m getting the error message shown in the title of this thread.
Here’s the relevant code in my timeline:
// Button functions
var buttonScript:Buttons = new Buttons();
// Button events
border.skip_intro_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonScript.buttonDimmer);
border.skip_intro_btn.addEventListener(MouseEvent.MOUSE_OUT, buttonScript.buttonLighter);
border.skip_intro_btn.addEventListener(MouseEvent.CLICK, buttonScript.jumpToPage);
border.main_menu.home_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonScript.buttonDimmer);
border.main_menu.home_btn.addEventListener(MouseEvent.MOUSE_OUT, buttonScript.buttonLighter);
border.main_menu.home_btn.addEventListener(MouseEvent.CLICK, buttonScript.jumpToPage);
border.main_menu.trailer_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonScript.buttonDimmer);
border.main_menu.trailer_btn.addEventListener(MouseEvent.MOUSE_OUT, buttonScript.buttonLighter);
border.main_menu.trailer_btn.addEventListener(MouseEvent.CLICK, buttonScript.jumpToPage);
border.main_menu.shop_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonScript.buttonDimmer);
border.main_menu.shop_btn.addEventListener(MouseEvent.MOUSE_OUT, buttonScript.buttonLighter);
border.main_menu.shop_btn.addEventListener(MouseEvent.CLICK, buttonScript.jumpToPage);
border.main_menu.contact_btn.addEventListener(MouseEvent.MOUSE_OVER, buttonScript.buttonDimmer);
border.main_menu.contact_btn.addEventListener(MouseEvent.MOUSE_OUT, buttonScript.buttonLighter);
border.main_menu.contact_btn.addEventListener(MouseEvent.CLICK, buttonScript.jumpToPage);
And here’s the code from the .as file:
package {
import flash.display.*;
import flash.events.*;
public class Buttons extends MovieClip {
public var buttonsActive = true;
function Buttons() {
}
public function buttonDimmer(evt:MouseEvent):void {
if (buttonsActive == true) {
evt.target.buttonMode = true;
evt.target.useHandCursor = true;
evt.target.gotoAndPlay("rollover");
}
}
public function buttonLighter(evt:MouseEvent):void {
if (buttonsActive == true) {
evt.target.gotoAndPlay("rollout");
}
}
public function jumpToPage(evt:MouseEvent):void {
if (buttonsActive == true) {
if (evt.target == border.skip_intro_btn) {
border.gotoAndPlay("buttons change");
gotoAndStop("home");
} else if (evt.target == border.home_btn) {
gotoAndStop("home");
} else if (evt.target == border.trailer_btn) {
gotoAndStop("trailer");
} else if (evt.target == border.shop_btn) {
gotoAndStop("home");
} else if (evt.target == border.contact_btn) {
gotoAndStop("home");
}
}
}
}
}
All of this code worked before I packaged it into an .as file.
I’d appreciate it if anyone could tell me why this is happening, but I’d also be very grateful if people could give me feedback on if I’m using this class for the right sort of thing. If all this kind of code would be better suited in the timeline, or if I’m just plain doing things incorrectly, please inform me!
Thanks!