Jump to content
Search Community

TweenMax reverse

Idans test
Moderator Tag

Recommended Posts

Hi,

I wrote this in order to change a color of button when the mouse is on it and to reverse it to the original color when the mouse moves out of it:

 

import com.greensock.*;

import flash.events.MouseEvent;

 

btn_mc.addEventListener(MouseEvent.MOUSE_OVER, myClickReaction);

btn_mc.addEventListener(MouseEvent.MOUSE_OUT, myOutReaction);

 

function myClickReaction (e:MouseEvent):void{

var myTween:TweenMax = new TweenMax(e.currentTarget, 1, {tint:0x33ff00});

}

 

function myOutReaction (e:MouseEvent):void{

myTween.reverse();

}

 

what did I do wrong?

 

Thank you

Link to comment
Share on other sites

Hi Idans,

I'm not entirely sure why that doesn't work, I'm sure Jack or Carl or someone a little more versed can explain, however try this code instead for your MOUSE_OUT function:

 

function myOutReaction (e:MouseEvent):void{
TweenMax(e.currentTarget, 1, {tint:null});
}

Link to comment
Share on other sites

Idans,

 

since you declared myTween inside myClickReaction(), you can't access it inside myOutReaction().

 

you could try

 

import com.greensock.*;
import flash.events.MouseEvent;

btn_mc.addEventListener(MouseEvent.MOUSE_OVER, myClickReaction);
btn_mc.addEventListener(MouseEvent.MOUSE_OUT, myOutReaction);

var myTween:TweenMax;

function myClickReaction (e:MouseEvent):void{
myTween = new TweenMax(e.currentTarget, 1, {tint:0x33ff00});
}

function myOutReaction (e:MouseEvent):void{
myTween.reverse();
}

 

X10,

 

your code should have been:

 

TweenMax.to(e.currentTarget, 1, {tint:null})

 

that should work fine, but it will create a new tween and not reverse the existing tween with the same timing.

Link to comment
Share on other sites

Ah yes, typo on my part there!! I will proof read my responses better next time.

Of course it should work if the var is defined outside the function - completely missed that, hence the typo I guess!

 

Thanks Carl!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...