/******* Gordons single frame menu system example ************/
// the basic idea is to control the visibilty of pages using a menu of buttons, all on one frame rather
// than have each page on a separate frame, and using gotoAndStop to move to the frame we want
// this appraoch greatly simplifies the quit page logic too.
// b1_MC, b2_MC & b3_MC are the movieClips we use as buttons - that constitute the menu
// p1_MC, p2_MC & p3_MC are the respective "pages" that "open" (are made visible)
// add a property to each of the movieClips we are using as buttons
// this new property, "openBox" points to the page each "button" will open
// this way, we can use one event function to handle the opening of all pages
// note you can add new properties to movieClips simply by stating them like this:
b1_MC.openBox = p1_MC;
b2_MC.openBox = p2_MC;
b3_MC.openBox = p3_MC; // this is our quit screen
/// adding properties in this way only works on movieClips - will not work on any other symbol type.
// make the all pages invisible at start up - if you want to have a startup page visible, set one of these to true, and currentPage = to the instance name of that movieClip
p1_MC.visible = false;
p2_MC.visible = false;
p3_MC.visible = false;
byebye_MC.visible = false;
//keep track of which "page" is open, so if a page is already open, we close it when we open another
// in this example, no page is open when we start so set this to null
var currentPage = null;
// add the event linstener to our movieClip buttons, and make the mouse appear as a hand
// when it rolls over the button ( buttonMode property )
b1_MC.addEventListener(MouseEvent.CLICK, showBoxes ); // showBoxes is the function that is called when the event is detected
b1_MC.buttonMode = true;
b2_MC.addEventListener(MouseEvent.CLICK, showBoxes );
b2_MC.buttonMode = true;
b3_MC.addEventListener(MouseEvent.CLICK, showBoxes ); // this is the quit button
b3_MC.buttonMode = true;
// set up the close button for each page, if you provide one
// note that the close buttons are inside of their respective pages
// hence we must name the instance of the parent movieClip first - e.g.: parent_instance_name.child_instance_name
p1_MC.close_btn.addEventListener(MouseEvent.CLICK, closeBox );
p2_MC.close_btn.addEventListener(MouseEvent.CLICK, closeBox );
//p3_MC - the quit button - has no close button, but rather yes quit and no don't quit buttons
// we handle these as special cases
p3_MC.yes_btn.addEventListener(MouseEvent.CLICK, showByeBye ); // show the quit screen
p3_MC.no_btn.addEventListener(MouseEvent.CLICK, returnToCurrent ); // user decideds not to quit, so we will show the current page, if there was one
byebye_MC.reload_btn.addEventListener(MouseEvent.CLICK, startOver ); // show the quit screen
// if a movieClip button is clicked on
// first check to see if a box is already open, if true close it
// then open the appropraite box, and set our currentPage pointer
// if the quit button was clicked (b3_MC) then handle that a little differently
function showBoxes( evt ){
if( currentPage != null ){ // make sure there is a current page showing before trying to close it...
currentPage.visible = false; // hide the currentPage
}
if( evt.target.name == "b3_MC" ){ // has the quit button been clicked?
showMenu( false ); // hide all the menu items, don't change currentPage value
}else{ // if not the quit button, handle normally - set the currentPage pointer to the button's current page
currentPage = evt.target.openBox
}
evt.target.openBox.visible = true; // show this button's page
}
// event that handles the close box in each of the pages
function closeBox( evt ){
// since the close button is inside the movieClip, and we want to hide the movieClip, the target needs to tell it's parent to close.
evt.target.parent.visible = false;
currentPage = null;
}
//hide or show the menu buttons when we click on quit
function showMenu( showOrHide ){ // showOrHide is a boolean passed to this function
b1_MC.visible = showOrHide;
b2_MC.visible = showOrHide;
b3_MC.visible = showOrHide;
}
function returnToCurrent( evt ){ // user decided not to quit
p3_MC.visible = false; // hide the quit button
if( currentPage != null ){ // since we allow the possiblity that no page is showing, we need to check ( see the closeBox function )
currentPage.visible = true; // show the page that was visible when the user clicked quit
}
showMenu( true );
}
function showByeBye( evt ){ // this is the end screen, but we provide a reload button in this example
p3_MC.visible = false;
byebye_MC.visible = true;
}
function startOver( evt ){ // the user has quit, but we give them a chance to reset and run again
// reset all back to startup state:
byebye_MC.visible = false;
showMenu( true );
currentPage = null;
}