Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
icekomo

liquid stage: Targeting a new X postion?

Recommended Posts

Hello,

I have a question, and it may be a simple one as I am no AS3 expert.

 

I have an object that is hooked up to a mouseOver event. When the mouse rolls over this object it moves it say 10 pixels to the left, and when it roll off, it moves that object back. The problem I ran into is that when i resize the window, it's still using the old x cords. So my question is what can I do to get the new x postion of that object each time the mouseEvent is called?

 

Do I use the update function for that info? And if so, how exactly.

 

Thanks!!

Link to comment
Share on other sites

You're using LiquidStage I assume, right? And that tweening object is pinned with LiquidStage?

 

You could just do a relative tween by putting the value in quotes. Like to move 10 pixels greater than the current x value, you'd do:

 

TweenMax.to(mc, 0.5, {x:"10"});

 

And to make it 10 less than the current value, do:

 

TweenMax.to(mc, 0.5, {x:"-10"});

 

Maybe I didn't understand your question though.

Link to comment
Share on other sites

No you told me just what I was looking for. Thanks!!!!

 

The only problem I run into with doing it this way, is that if user rolls off of that object before it's animation is complete, it sends it back the other way past it's original start postion, because it's using the x postion of that object during it's animation. If that makes sense? And I want the user to have the ability to roll off of the object before it's complete if they so choose to do so.

 

Thanks.

Link to comment
Share on other sites

My thinking for this problem is to capture the the current X position of that movie clip at it's starting point, call this StartX, and when the user rolls off of that object to then capture that X position call this backX and then use backX number and subtract that from startX. But I can't seem to get this to work.

Link to comment
Share on other sites

There are many ways to tackle this - here's one idea:

 

var xChange:Number = 10; //how much to change x on rollOver
var tween:TweenMax; //we need a reference to the tween to find out how far along it is.

function rollOverHandler(event:MouseEvent):void {
   var ratio:Number = (tween != null) ? tween.ratio : 1;
   tween = new TweenMax(mc, 1, {x:mc.x + ratio * xChange});
}

function rollOutHandler(event:MouseEvent):void {
   var ratio:Number = tween.ratio;
   tween = new TweenMax(mc, 1, {x:mc.x - ratio * xChange});
}

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