Hello all,
I’m trying to clean up my code for an animation I created. I’m hoping by doing this, my animation will stop being as buggy and/or I can more easily figure out why its being buggy. I think that variables are the way to go so I read up on them and have a decent idea of what I need to do. But what sounds good in my head doesn’t seem to work on screen.
So basically I would like to take my three buttons called card1, card2 and card3 and combine their functions. All the code for each button looks exactly like the code below (except for the mc name of course)
card1.addEventListener(MouseEvent.ROLL_OVER, overhandler);
function overhandler(event:MouseEvent):void {
if(accordionAnimating == false){
var _posX:Number = card1.x -8;
TweenLite.to(card1, .5,{x:_posX, ease:Linear.easeNone, onComplete:reverseAni});
}
}
function reverseAni():void {
var _posX:Number = card1.x +8;
TweenLite.to(card1, .5,{x:_posX, ease:Linear.easeNone });
}
From what I learned about arrays the following code should work:
var allCards:Array = new Array (card1, card2, card3);
var _negX:Number = callCards.x -8;
var _posX:Number = callCards.x +8;
card1.addEventListener(MouseEvent.ROLL_OVER, overhandler);
card2.addEventListener(MouseEvent.ROLL_OVER, overhandler);
card3.addEventListener(MouseEvent.ROLL_OVER, overhandler);
function overhandler(event:MouseEvent):void {
if(accordionAnimating == false){
TweenLite.to(allCards, .5,{x:_negX, ease:Linear.easeNone, onComplete:reverseAni});
}
}
function reverseAni():void {
TweenLite.to(allCards, .5,{x:_posX, ease:Linear.easeNone });
}
Of course it doesn’t work. I think it is something to do with my x position. I need the card to move -8 then +8 on rollover, relative to the cards new position. Plus I don’t believe that the function is reading my var _negX and _posX code. Any thoughts???
Thanks so much in advance!