Jump to content
Search Community

TweenMax evt.target problem

Sbml test
Moderator Tag

Recommended Posts

Hello

 

I have a Image XML menu that works well, but with a litle problem with target in TweenMax. I will post only the code that is relevant to resolve the problem, I hope :D .

 

I have a MC in library, and inside I have 3 movie clips, img_mc, bg_mc (this is a background for text) and title_mc (inside this mc I have a textfield named title-txt).

 

I create a for loop for the MC, so I use e.currentTarget in my tween animations.

 

When I hovered the title_mc is suposed to scale the background, but because bg_mc are back the hover don't works. I do not know how to target the title_mc for on MOUSE:OVER scale the bg_mc.

 

MY CODE:

 

	for (var i:Number = 0; i < my_total; i++)
{
	//CREATE THE LOOP FOR MOVIE CLIP THAT I HAVE IN LIBRARY WITH THE CLASS "menu_item" 
	var MC:MovieClip = new menu_item();
	MC.id = "i" + i;
	MC.label = my_menu[i]. @ LABEL;
	MC.name = "mc" + i;

 

//INITIAL ANIMATIONS
	TweenLite.to(MC, 0, {alpha:0});
	TweenMax.to(MC.container_mc.img_mc, 0, {colorMatrixFilter:{colorize:0xffffff, amount:1}});
	TweenMax.to(MC, 2, {dropShadowFilter:{color:0x000000, alpha:0.7, blurX:15, blurY:15, distance:15}});

 

//ANIMATION EVENTS
MC.container_mc.bg_mc.addEventListener(MouseEvent.MOUSE_OVER, hover_bg);
MC.container_mc.bg_mc.addEventListener(MouseEvent.MOUSE_OUT, out_bg);

function hover_bg(e:MouseEvent)
{
TweenLite.to(e.currentTarget,1,{scaleY:1.2,ease:Quad.easeInOut});
TweenLite.to(e.currentTarget,1,{alpha:0.8});
}
function out_bg(e:MouseEvent)
{
TweenLite.to(e.currentTarget,1,{scaleY:1,ease:Quad.easeInOut});
TweenLite.to(e.currentTarget,1,{alpha:0.6});
}

 

This Last piece of code don't works because title_mc is over bg_mc.

If I put in event listener MC.container_mc.title_mc.addEventListener(MouseEvent.MOUSE_OUT, out_bg); the Text will scale too, and I don't want this...

 

Thanks

Link to comment
Share on other sites

If you don't want title_mc to interact with the mouse at all, you can simply do:

 

title_mc.mouseEnabled = false;

 

Does that answer your question?

 

Also make sure you set the OverwriteManager's mode to AUTO or else you'll need to set overwrite:false on your 2nd tweens to prevent the alpha tweens from overwriting the scaleY tweens. See http://www.greensock.com/overwritemanager/ for details. This is only necessary for TweenLite and TweenNano - TweenMax enables AUTO mode by default for you.

Link to comment
Share on other sites

Works with more a couple of settings:

 

MC.container_mc.title_mc.hitArea = MC.container_mc.bg_mc;
MC.container_mc.title_mc.mouseEnabled = false;
MC.container_mc.title_mc.mouseChildren = false;

 

One question, if I want to add the event to one clip and target another in TweenMax how can I do That ?

 

Thanks for the help

Link to comment
Share on other sites

use ROLL_OVER instead of MOUSE_OVER to save yourself a lot of headache. MOUSE_OVER is great when you really understand what it does, but more often than not leads to trouble.

 

instead of figuring out your code, consider a MoveClip with the instance name of nav1 sitting on the stage.

nav1 contains a MovieClip which is a solid color shape name bg

nav1also contains a TextField called label_txt.

 

to have the label_txt and bg change color on rollOver of the container called nav1 simply do:

 

nav1.addEventListener(MouseEvent.ROLL_OVER, navOver);

 

function navOver(e:MouseEvent):void{

TweenMax.to(e.target.bg, .5, {tint:0xffff00});

TweenMax.to(e.target.label_txt, .5, {tint:0x00ccff});

}

 

if you have multiple buttons nav1, nav2, nav3... you can add the eventListeners in a for loop.

 

it helps to have a strong understanding of difference between ROLL_OVER and MOUSE_OVER and target and currentTarget.

read the following:

 

http://www.greensock.com/tweening-tips/ (SEE TIP #7)

http://www.wastedpotential.com/?p=10

http://www.snorkl.tv/2010/08/assign-eve ... enttarget/

 

it definitely took me awhile to understand this. the interactive example on wasted potential really helped me. hopefully one of the 3 links above hits home

 

Carl

Link to comment
Share on other sites

Hello, I never understand well the diferences between MOUSE_OVER / OUT and ROLL_OVER /OUT ,but the tutorials are very good.

I change my Mouse Events to ROLL_OVER and ROLL_OUT and my tweens are much smoother than before. :D

Thanks for the Tips !

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