Hi everyone. Im just starting out using AS3 and have been following some tutorials from all over the place. Ive tried to figure out why this simple website code only seems to load the last page all the time.
Im sure its easy but i just cant for the life of me figure it out.
Thanks a lot in advance.
import fl.transitions.;
import fl.transitions.easing.;
//assigns click listeners for each menu button
aboutBUTTON.addEventListener (MouseEvent.CLICK, buttonClicked);
galleryBUTTON.addEventListener (MouseEvent.CLICK, buttonClicked);
termsBUTTON.addEventListener (MouseEvent.CLICK, buttonClicked);
//Makes the buttons look like buttons (hand apears when hovering over)
aboutBUTTON.buttonMode = true;
galleryBUTTON.buttonMode = true;
termsBUTTON.buttonMode = true;
//this loader is used to load the external swf files
var loader:Loader;
//URLrequest stores the path of the file to be loaded
var urlRequest:URLRequest;
//This array holds all the tweens so that dont get garbage collected
var tweens:Array = new Array();
//Stores the current page we are displaying
var currentPage:MovieClip = null;
//Stores the next page we are going to display
var nextPage:MovieClip = null;
//This event is called when a button is clicked
function buttonClicked (e:Event):void{
//creates a new loader instance
loader = new Loader();
//If we clicked the first button we load the first page
if (e.target == aboutBUTTON) {
urlRequest = new URLRequest ("about.swf");
loader.load(urlRequest);
}
//if we clicked the second button then we load the second page
else if (e.target == galleryBUTTON){
urlRequest = new URLRequest ("gallery.swf");
loader.load(urlRequest);
}
//We load page three as we know that the other two pages havent been
//chosen
else{
urlRequest = new URLRequest (“terms.swf”);
loader.load(urlRequest);
}
//We want to know when the next page has finished loading
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fileLoaded);
}
//This function is called when we have finished loading a content page.
function fileLoaded(e:Event):void{
//The loader contains the page we are going to display
nextPage = e.target.content;
//Lets animate the current content away from the stage
// First lets check to see if there is a current page on stage
if (currentPage != null){
//tween the current page from left to right
var tweenX:Tween = new Tween(currentPage, "x", Regular.easeOut,
currentPage.x, 500, 1, true);
//Decrease the alpha to zero
var tweenAlpha:Tween = new Tween (currentPage, "alpha", Regular.easeOut,
1, 0, 1, true);
//Push the tweens into arrays
tweens.push(tweenX);
tweens.push(tweenAlpha);
//CurrentPageGone will be called when the tween is finished
tweenX.addEventListener(TweenEvent.MOTION_FINISH, currentPageGone);
}
//There is no current page, so we can animate the next page to
//the stage. The animation is done in the showNextPage function.
else{
showNextPage();
}
}
//This function animates and displayes the next page
function showNextPage():void {
//Tween the next page from left to the center
var tweenX:Tween = new Tween(nextPage, "x", Regular.easeOut,
-200, 0, 1, true);
//Tween the alpha to from 0 to 1
var tweenAlpha:Tween = new Tween(nextPage, "alpha", Regular.easeOut,
0, 1, 1, true);
//Push the tweens into an array
tweens.push(tweenX);
tweens.push(tweenAlpha);
//Add the next page to the stage
addChild(nextPage);
//Next page is now our current page
currentPage = nextPage;
}
//This function is called when the current page has been animated away
function currentPageGone(e:Event):void {
//Remove the current page completely
removeChild(currentPage);
//Let's show the next page
showNextPage();
}