Hi everyone,
This is my first ever post to this forum. I've been getting into TweenMax and TimelineMax recently, but I seem to have hit a brick wall with my code.
I've created a menu system that animates new buttons onto the screen when required, then sends them away when not. Works at first until you try to loop through the process again. It seems to just ignore the listeners I created!
I have listed the code below so you can see the problem for yourself: (Note only food, home and wine buttons work)
Any help at all would be greatly appreciated!
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.TimelineMax;
import flash.events.MouseEvent;
//These are the titles for the buttons
home_b.title_box.title.text = "Home";
food_b.title_box.title.text = "Food & Wine";
tea_b.title_box.title.text = "Tea & Coffee";
gallery_b.title_box.title.text = "Gallery";
events_b.title_box.title.text = "Events";
about_b.title_box.title.text = "About Us";
lunch_b.title_box.title.text = "Lunch";
six_b.title_box.title.text = "Six-Five Special";
pullman_b.title_box.title.text = "Pullman Dining";
wine_b.title_box.title.text = "Winelist";
wine_b.title_box.title.text = "Winelist";
white_b.title_box.title.text = "White";
red_b.title_box.title.text = "Red";
rose_b.title_box.title.text = "Rose";
champ_b.title_box.title.text = "Champagne";
//These are the buttons starting places on the screen
home_b.x = 0;
home_b.y = 180;
food_b.x = 0;
food_b.y = 210;
tea_b.x = 0;
tea_b.y = 240;
gallery_b.x = 0;
gallery_b.y = 270;
events_b.x = 0;
events_b.y = 300;
about_b.x = 0;
about_b.y = 330;
lunch_b.x = -150;
lunch_b.y = 60;
six_b.x = -150;
six_b.y = 90;
pullman_b.x = -150;
pullman_b.y = 120;
wine_b.x = -150;
wine_b.y = 150;
white_b.x = -150;
white_b.y = 180;
red_b.x = -150;
red_b.y = 210;
rose_b.x = -150;
rose_b.y = 240;
champ_b.x = -150;
champ_b.y = 270;
//Buttons are currently invisible
home_b.alpha = 0;
food_b.alpha = 0;
tea_b.alpha = 0;
gallery_b.alpha = 0;
events_b.alpha = 0;
about_b.alpha = 0;
lunch_b.alpha = 0;
six_b.alpha = 0;
pullman_b.alpha = 0;
wine_b.alpha = 0;
white_b.alpha = 0;
red_b.alpha = 0;
rose_b.alpha = 0;
champ_b.alpha = 0;
//Animate buttons onto screen
var ShowMenu:TimelineMax = new TimelineMax({onComplete:ListenOut});
ShowMenu.append( TweenMax.to(home_b, 0.3, {alpha:1, y:0, ease:Sine.easeIn}) );
ShowMenu.append( TweenMax.to(food_b, 0.3, {alpha:1, y:30, ease:Sine.easeIn, delay:-0.2}) );
ShowMenu.append( TweenMax.to(tea_b, 0.3, {alpha:1, y:60, ease:Sine.easeIn, delay:-0.2}) );
ShowMenu.append( TweenMax.to(gallery_b, 0.3, {alpha:1, y:90, ease:Sine.easeIn, delay:-0.2}) );
ShowMenu.append( TweenMax.to(events_b, 0.3, {alpha:1, y:120, ease:Sine.easeIn, delay:-0.2}) );
ShowMenu.append( TweenMax.to(about_b, 0.3, {alpha:1, y:150, ease:Sine.easeIn, delay:-0.2}) );
function ListenOut():void{
food_b.addEventListener(MouseEvent.MOUSE_UP, openFood);
}
//If food button is pressed, do this:
function openFood(event:MouseEvent):void{
showFood.play();
}
//Animate buttons down, then look for food list
var showFood:TimelineMax = new TimelineMax({paused:true, onComplete:ListenOut2});
var food:Array = new Array(lunch_b, six_b, pullman_b, wine_;
//Food list then wine list
showFood.append( TweenMax.to(about_b, 0.3, {alpha:1, y:270, ease:Sine.easeIn}) );
showFood.append( TweenMax.to(events_b, 0.3, {alpha:1, y:240, ease:Sine.easeIn, delay:-0.2}) );
showFood.append( TweenMax.to(gallery_b, 0.3, {alpha:1, y:210, ease:Sine.easeIn, delay:-0.2}) );
showFood.append( TweenMax.to(tea_b, 0.3, {alpha:1, y:180, ease:Sine.easeIn, delay:-0.2}) );
showFood.appendMultiple( TweenMax.allTo(food, 0.3, {alpha:1, x:50, ease:Sine.easeOut}, 0.1) );
function ListenOut2():void{
//Home button now active
home_b.addEventListener(MouseEvent.MOUSE_UP, closeFood);
//Wine button now active
wine_b.addEventListener(MouseEvent.MOUSE_UP, openWine);
}
function closeFood(event:MouseEvent):void{
//Home button no longer takes us home
home_b.removeEventListener(MouseEvent.MOUSE_UP, closeFood);
//Wine button no longer active
wine_b.removeEventListener(MouseEvent.MOUSE_UP, openWine);
showFood.reverse();
}
function openWine(event:MouseEvent):void{
showWine.play();
}
var showWine:TimelineMax = new TimelineMax({paused:true, onComplete:ListenOut3});
var wines:Array = new Array(white_b, red_b, rose_b, champ_;
//These buttons slide down
showWine.append( TweenMax.to(about_b, 0.3, {alpha:1, y:390, ease:Sine.easeIn}) );
showWine.append( TweenMax.to(events_b, 0.3, {alpha:1, y:360, ease:Sine.easeIn, delay:-0.2}) );
showWine.append( TweenMax.to(gallery_b, 0.3, {alpha:1, y:330, ease:Sine.easeIn, delay:-0.2}) );
showWine.append( TweenMax.to(tea_b, 0.3, {alpha:1, y:300, ease:Sine.easeIn, delay:-0.2}) );
showWine.appendMultiple( TweenMax.allTo(wines, 0.3, {alpha:1, x:100, ease:Sine.easeOut}, 0.1) );
function ListenOut3():void{
//Home button no longer takes you home from food
home_b.removeEventListener(MouseEvent.MOUSE_UP, closeFood);
home_b.addEventListener(MouseEvent.MOUSE_UP, closeWine);
//wine button no longer active
wine_b.removeEventListener(MouseEvent.MOUSE_UP, openWine);
}
function closeWine(event:MouseEvent):void{
closeEverything.play();
}
var closeEverything:TimelineMax = new TimelineMax({paused:true, onComplete:ListenOut});
var FoodWineArray:Array = new Array(champ_b, rose_b, red_b, white_b, wine_b, pullman_b, six_b, lunch_;
closeEverything.appendMultiple(TweenMax.allTo(FoodWineArray, 0.3, {alpha:0, x:-150, ease:Sine.easeIn}, 0.1) );
closeEverything.append( TweenMax.to(tea_b, 0.3, {alpha:1, y:60, ease:Sine.easeIn}) );
closeEverything.append( TweenMax.to(gallery_b, 0.3, {alpha:1, y:90, ease:Sine.easeIn, delay:-0.2}) );
closeEverything.append( TweenMax.to(events_b, 0.3, {alpha:1, y:120, ease:Sine.easeIn, delay:-0.2}) );
closeEverything.append( TweenMax.to(about_b, 0.3, {alpha:1, y:150, ease:Sine.easeIn, delay:-0.