Jump to content
Search Community

using tween max with a switch statement problem

sherwoodbear79 test
Moderator Tag

Recommended Posts

Hi all,

 

Got an issue with using tweenmax. I have a play() function on a case of btn being clicked but nothing happens! no errors just nothing!

But when I have the function in a separate function (alone) it works. Any thoughts?

 

the idea is to mimic a mac menu so mouse over - enlarges icon and mouse out - icon returns to original size. I was hoping to use a switch to reduce code.

Help woud be very much appreciated!!!!

 

here is my cde

 

var buttonTween1:TweenMax = new TweenMax(btn1, .5, {scaleX: 1.5, scaleY:1.5, paused:true});

var buttonTween2:TweenMax = new TweenMax(btn2, .5, {scaleX: 1.5, scaleY:1.5, paused:true});

 

 

btn1.addEventListener(MouseEvent.MOUSE_OVER, overBtn);

btn2.addEventListener(MouseEvent.MOUSE_OVER, overBtn);

 

 

 

function overBtn(e:Event):void{

switch(e.target.name){

 

case"btn1":

buttonTween1.play();

break;

case"btn2":

buttonTween2.play();

break;

 

 

 

}

}

Link to comment
Share on other sites

hmmm, i used your code exactly as is except I had different instance names on my buttons and it worked fine.

 

try putting

 

trace(e.target.name);

 

right before the switch statement like so

 

function overBtn(e:Event):void{

trace(e.target.name);
switch(e.target.name){

case"btn1":
buttonTween1.play();
break;
case"btn2":
buttonTween2.play();
break;

}
}

 

make sure it is tracing btn1 or btn2

 

unless there is a good reason to use MOUSE_OVER... I would suggest ROLL_OVER instead.

Link to comment
Share on other sites

unless there is a good reason to use MOUSE_OVER... I would suggest ROLL_OVER instead.

Yep, this could be the root of your problem actually. See http://www.greensock.com/tweening-tips/#mouseover

 

Basically, if your button has any children and you roll your mouse over them, the MOUSE_OVER event's "target" will point at the child, not your button. You'd be better off using "currentTarget". Or, as Carl suggested, just use ROLL_OVER/ROLL_OUT event listeners.

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...