Jump to content
Search Community

dynamicProps without time duration

peterPotter test
Moderator Tag

Recommended Posts

Essentially I want to use dynamicProps and TweenLite only to replace the following code, which is using the Enter_Frame event and TweenLite.

 

 stage.addEventListener(Event.ENTER_FRAME, moveMC);
    private function moveMC(e:Event):void
	      {
		var distx:Number = mouseX / stage.stageWidth;
		var disty:Number = mouseY / stage.stageHeight;
		TweenLite.to(mainClip.panel_mc, 2, {rotationY:(-8 + (16*distx)), rotationX:(8 - (16*disty)), ease:Expo.easeOut });						
	     }

// Instead of using the Enter_Frame event, I want to do:
mainClip.panel_mc.addEventListener(MouseEvent.ROLL_OVER, moveMC);

private function moveMC(e:MouseEvent):void
	      {
                     TweenLite.to(mainClip.panel_mc, 4, {dynamicProps:{rotationY:(-8 + (16*getDistX)), rotationX:(8 - (16* getDistY))}, ease:Expo.easeOut });	
// the 4 second duration cannot work here because I want to keep rotating until the user MouseEvent.ROLL_OUT of the mainClip.panel_mc clip				
	     }
;

Link to comment
Share on other sites

A tween by its very nature must have a duration since it takes a property from value a to value b over a certain amount of time. When there is no time defined, there's no way for it to know how much change to implement each frame/second/update. Also, it looks like you're using dynamicProps incorrectly - each property inside the dynamicProps object should be associated with a function but you're hard-coding numeric values instead. Like:

 

TweenLite.to(mc, 2, {dynamicProps:{x:getMouseX, y:getMouseY}});
function getMouseX():Number {
   return this.mouseX;
}
function getMouseY():Number {
   return this.mouseY;
}

 

You could do an ENTER_FRAME that keeps recreating the tween while the mouse is over the object, making it get closer and closer to its destination without ever hitting it, and when you rollout, just remove the ENTER_FRAME listener. Just a thought. Oh, and I'd make sure overwrite is true for those tweens (unless you have other tweens of the same object that need to keep going) - this would improve performance a bit.

Link to comment
Share on other sites

I was using dynamicProps correctly, getDistX is a function that returns the distx:Number = mouseX / stage.stageWidth;

 

Thanks for the following thought, "You could do an ENTER_FRAME that keeps recreating the tween while the mouse is over the object." I will try that, I am confident I will get it to work.

Link to comment
Share on other sites

I was using dynamicProps correctly, getDistX is a function that returns the distx:Number = mouseX / stage.stageWidth;

 

But that wouldn't work in the code you posted:

TweenLite.to(mainClip.panel_mc, 4, {dynamicProps:{rotationY:(-8 + (16*getDistX)), rotationX:(8 - (16* getDistY))}, ease:Expo.easeOut });  

 

Because (-8 + (16*getDistX)) is not a function. The property must literally refer to a function, not the result of a function or a mathematical equation that uses a function in part of it.

 

Hope the other suggestion works out.

Link to comment
Share on other sites

Aha, got it. Thanks for all your help, hopefully I wouldn't have any more questions.

 

Thanks very much for the wonderful GreenSock Tweening Platform that is far superior to the other three well-known Tweening engines, including the Flash built-in Tween engine that I personally dislike.

Link to comment
Share on other sites

  • 3 weeks later...

having trouble with the as2 dynamicProps usage. the as2 example has as3 references -

mouseX

instead of

_xmouse

for example.

 

after changing these over, nothing happens. (i have a licence :) )

 

import com.greensock.TweenLite;
import com.greensock.plugins.TweenPlugin;
import com.greensock.plugins.DynamicPropsPlugin;
TweenPlugin.activate([DynamicPropsPlugin]); //activation is permanent in the SWF, so this line only needs to be run once.

function getMouseX():Number {
return this._xmouse;
}
function getMouseY():Number {
return this._ymouse;
}
TweenLite.to(my_mc, 3, {dynamicProps:{_x:getMouseX(), _y:getMouseY()}});

Link to comment
Share on other sites

You put "()" after your functions which tells Flash to call the function immediately. So you were assigning the RESULT of the function to the properties instead of the actual function.

 

BAD: TweenLite.to(my_mc, 3, {dynamicProps:{_x:getMouseX(), _y:getMouseY()}});

 

GOOD: TweenLite.to(my_mc, 3, {dynamicProps:{_x:getMouseX, _y:getMouseY}});

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