// import tweening classes you'll need for button animations
import gs.*;
import gs.easing.*;
// declare variables for the nested buttons
var b1:MovieClip = navBar.btn1;
var b2:MovieClip = navBar.btn2;
var b3:MovieClip = navBar.btn3;
var b4:MovieClip = navBar.btn4;
var b5:MovieClip = navBar.btn5;
// label the buttons
b1.btnText.text = "button 1";
b2.btnText.text = "button 2";
b3.btnText.text = "button 3";
b4.btnText.text = "button 4";
b5.btnText.text = "button 5";
// declare an array of the buttons
var navArray:Array = [ b1, b2, b3, b4, b5 ];
// declare a variable that will be assigned a value in the click function
var btnName:String = "";
// intitialize the site.
function loadSite():void
{
// tween the buttons onto the stage from specified coordinates.
TweenGroup.allFrom(navArray, 1, {delay:1, x:0, alpha:0, ease:Expo.easeInOut, onComplete:enableNavBar});
}
// call the loadSite function.
loadSite();
// add an event listener to the buttons, so they will response to mouse events
function enableNavBar():void
{
// mouse event listener for mouse over is added to memory.
navBar.addEventListener(MouseEvent.MOUSE_OVER, btnOver, false, 0, true);
// disable mouse events for the parent movieclip that contains our buttons.
navBar.mouseEnabled = false;
}
// the mouse over function; this is called by the event listener when the mouse is over a button.
function btnOver(e:MouseEvent):void
{
// event listeners for mouse out and click are added to memory
navBar.addEventListener(MouseEvent.MOUSE_OUT, btnOut, false, 0, true);
navBar.addEventListener(MouseEvent.CLICK, btnClick, false, 0, true);
// button animation
TweenLite.to(e.target, .6, {y:-20, ease:Elastic.easeOut});
}
// the mouse out function; this is called by the event listener when the mouse exits a button
function btnOut(e:MouseEvent):void
{
// button animation
TweenLite.to(e.target, .4, {y:0, ease:Back.easeIn});
}
// the mouse click function; this called by the event listener when the mouse clicked on a button
function btnClick(e:MouseEvent):void
{
// remove mouse out and mouse click listeners; we don't need them right now
navBar.removeEventListener(MouseEvent.MOUSE_OUT, btnOut);
navBar.removeEventListener(MouseEvent.CLICK, btnClick);
// the variable is assigned a value; "e.target.name" this captures, as a String, the instance name of the button that was clicked.
btnName = e.target.name;
// the trace command is used to confirm that our variable is working correctly
trace(btnName + " was clicked");
// this is a simple loop that resets all of the buttons
var btnNum:Number = 5;
for (var i:Number = 1; i<=btnNum; i++)
{
this["b" + i].mouseEnabled = true;
TweenLite.to(this["b" + i], .4, {y:0, ease:Back.easeIn});
}
// this disables the button that was clicked and sets it to the clicked status
e.target.mouseEnabled = false;
TweenLite.to(e.target, 0, {delay:0, y:-20});
// finally, we use the variable "bynName" to send the playhead to the frame label that matches the instance name of the button that was clicked.
pages.gotoAndStop(btnName);
}