I’m trying to build myself a website by using classes and movie clips to build a ‘page’ instead of the standard frame (and timeline) method. For lack of a better description, I’m calling it class navigation.
I found out about class navigation here:
http://www.theflashconnection.com/content/better-flash-navigation-using-as3-classes#comment-75
What I have done so far:
I have a main .fla file, from which I create Movie Clips (the website pages), then create a class to go with them. (In an .as file, this is where I write all the AS3.) I then remove the movie from the stage.
There is also a “Main” AS file to control the others. This is where I’m trying to load each individual ‘page’ (class and movie clip) from.
The buttons I am using are on the stage of the main .fla, each labeled with instances. The buttons are not button symbols, but are actually movie clips I’m using as buttons.
THE PROBLEM:
Although I have everything named, and scripted. When I preview it, I don’t get any output errors, any bugs or stuff like that. My movie-clip-buttons have a mouse-over event on them, and THAT works, but I can’t ‘move’ between the screens.
Here is the code from my Main.as file that’s acting as the ‘controller’ … sorry about the mess of comments, I’m afraid to delete things until I know for sure it’s the problem.
ANY Help, hints, suggestions you can offer would be fantastic! I’m really stuck I don’t know where to go from here to trouble shoot and keep going forward.
package {
import flash.display.*;
import flash.events.*;
import flash.filters.BlurFilter;
public class MainBase extends MovieClip {
private var home:Home; //these are the two page classes
private var about:About; // I've got scripted so far
private var currentScreen:MovieClip; //used later to 'clear' the stage
private var bfFilter:BlurFilter = new BlurFilter (10, 0, 3);
public function MainBase() {
//trace("bananas are yummy!");
//above was just to test it's working. It does.
home = new Home();
addChild(home);
currentScreen = home;
about = new About();
//future pages will be listed here
}
public function menu():void{
homeMC.buttonMode = true; //homeMC is the button
//instance name to get 'home'
homeMC.addEventListener(MouseEvent.CLICK, homeHandler);
homeMC.mouseEnabled = true;
function homeHandler(event:MouseEvent):void {
removeChild(currentScreen); //removes previous 'page'
addChild(home); //adds class/movie clip to stage
currentScreen = home; //sets up for easy removeChild later on
//trace("bananas are yummy!");
homeMC.gotoAndStop("_down"); //the 'down' stage of my button
}
aboutMC.buttonMode = true;
aboutMC.addEventListener(MouseEvent.CLICK, aboutHandler);
function aboutHandler(event:MouseEvent):void {
//about = new About(); //creates new instance of 'About' page
removeChild(currentScreen);
addChild(about);
currentScreen = about;
//aboutMC.mouseEnabled = false;
//aboutMC.buttonMode = false;
}
This is what one of the pages (stripped down) looks like
package {
import flash.display.*;
import flash.events.*;
public class About extends MovieClip {
public function About() {
addEventListener(Event.ADDED_TO_STAGE, addedHandler);
addEventListener(Event.REMOVED_FROM_STAGE, removedHandler);
}
private function addedHandler(event:Event):void {
this.x = stage.stageWidth / 2;
this.y = stage.stageHeight / 2;
trace("yeah!")
}
private function removedHandler(event:Event):void {
}
}
}