In my quest to learn ActionScript 3.0 I have stumbled across another situation where I know what I need to do, but just can’t figure out how to do. I have written code to animate a menu with 3 buttons. These 3 buttons reside in a seperate class file known as MenuButtons.as and I am animating them within my Main.as file which builds the application and places the relevant details onto the stage.
So in my Main.as file I have written the animation code that I would like to use to animate the buttons. Whenever a button is clicked, an event is dispatched which a handler listeners for then executes the relevant function. So the function for animating my 3 buttons looks like this (bear in mind that the buttons are arranged in a place holder in MenuButtons.as which in turn is loaded in a new MovieClip in the Main.as file)
function menuAnimate(e:Event):void
{
tweenMenu = new Tween(menuButtons.contactMeBtn,"y",Strong.easeInOut,200,300,0.2,true);
tweenMenu.addEventListener(TweenEvent.MOTION_FINISH, button2);
function button2(event:TweenEvent):void
{
tweenMenu = new Tween(menuButtons.galleryBtn,"y",Strong.easeInOut,100,300,0.2,true);
tweenMenu.addEventListener(TweenEvent.MOTION_FINISH, button3);
function button3(event:TweenEvent):void
{
tweenMenu = new Tween(menuButtons.aboutMeBtn,"y",Strong.easeInOut,0,300,0.2,true);
}
}
tweenLogo = new Tween(myImageLoader,"x",Strong.easeInOut,0,stage.width * -1,1,true);
}
I also tween the logo from here too. It works fine which is great, but is there a way I can make this code more simpler? I may not be able to and I have tried to find my answer online but alas I cannot find what I am looking for.
I am loving how I am learning something new each day and by building up slowly I am learning more functionality and broadening my knowledge of ActionScript (although some of it is very confusing!)
Is there any good websites out there that can help? I have a subscription with Lynda.com but i find that their explanations can sometimes be hard to understand. I love text based tutorials where I can follow at my own pace.
Thank you
I would very much recommend getting to know TweenMax (http://www.greensock.com) which is a very powerful tweening engine.
Using TweenMax your function could be done in one line of code:
TweenMax.allTo([menuButtons.contactMeBtn, menuButtons.galleryBtn, menuButtons.aboutMeBtn], .2, {y:300, alpha:1 , ease:Strong.easeInOut, onComplete: tweenLogo}, .2);