Hello everyone!
Ive been having some trouble trying to figure out why this bit of code (which i put together from tutorials) only loads the “terms and conditions” swf fil.
I have three buttons, all of which seem to only load the terms and conditions button. Have i missed anything out or written anything wrong?
Any help would be greatly appreciated as I am no coder and am trying to learn through trial and error.
Thanks in advance.
my code:
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();
}