Jump to content
Search Community

TweenMax Bezier onComplete Not Working

xparrot test
Moderator Tag

Recommended Posts

I'm new to green sock, but very well versed in Flash and ActionScript. I cannot for the life of my get an onComplete to work. Here is my code, maybe I have it in the wrong place?: 

function RedWineBounce04(event:TweenEvent):void
{
	TweenMax.to(mcRedWines, tweenSpeedBounce, {bezier:{type:"quadratic", values:[{x:X_02_RedWines, y:Y_02_RedWines}, {x:(X_02_RedWines+BounceDistance), y:(Y_02_RedWines-BounceDisplacement)}, {x:(X_02_RedWines+125), y:Y_02_RedWines}], ease:Linear.easeNone, onComplete:MadeIt}});
	X_02_RedWines = X_02_RedWines + 125;
	function MadeIt(event:TweenEvent):void
	{
		trace("Made It");
	}


}
Link to comment
Share on other sites

Hi and welcome to the GreenSock forums.

 

It appears you have your onComplete and ease property as part of the object that gets passed to the BezierPlugin. You just need to move them outside that object as shown below

TweenMax.to(mcRedWines, tweenSpeedBounce, {bezier:{type:"quadratic", values:[{x:X_02_RedWines, y:Y_02_RedWines}, {x:(X_02_RedWines+BounceDistance), y:(Y_02_RedWines-BounceDisplacement)}, {x:(X_02_RedWines+125), y:Y_02_RedWines}]},
ease:Linear.easeNone, onComplete:MadeIt});
Link to comment
Share on other sites

That error has to do with the fact that your madeIt() function is expecting a TweenEvent and its not getting one.

Your error does though confirm that madeIt() is being called now.

 

When using callbacks like onComplete a TweenEvent is not passed to the callback.

 

You need to use onCompleteListener as listed in the docs (which is different than onComplete)
 

onCompleteListener : Function [AS3 only] - A function that should be called (and passed an event parameter) each time the tween completes. Identical to onComplete except that the function will always be passed an event parameter whose target property points to the tween. It's the same as doing myTween.addEventListener("complete", myFunction);. Unless you need the event parameter, it's better/faster to use onComplete.

 

Also if you want to add event listeners after a tween is created you can use addEventListener

Link to comment
Share on other sites

I looked at onCompleteListener and tried that too. This is the error I get when using onCompleteListener:

 

TypeError: Error #1034: Type Coercion failed: cannot convert com.greensock.events::TweenEvent@53efcf61 to fl.transitions.TweenEvent.

at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.greensock::TweenMax/render()
at com.greensock.core::SimpleTimeline/render()
at com.greensock.core::Animation$/_updateRoot()
Link to comment
Share on other sites

Are you using import fl.transitions.TweenEvent; somewhere in your code? Do you need to be?

Perhaps auto complete put that in. I would remove it if is there and it isn't absolutely necessary for your project as it appears to be causing a problem with our TweenEvent.

 

If that doesn't fix it, please post a zip of your file (as simplified as possible to replicate the error) so that we can compile it and dig deeper.

 

thanks

Link to comment
Share on other sites

Yes, if you need to simply call a function and you don't need the TweenEvent for inspection just use an onComplete callback
TweenMax.to(mcRedWines, tweenSpeedBounce, {bezier:{type:"quadratic", values:[{x:X_02_RedWines, y:Y_02_RedWines}, {x:(X_02_RedWines+BounceDistance), y:(Y_02_RedWines-BounceDisplacement)}, {x:(X_02_RedWines+125), y:Y_02_RedWines}], ease:Linear.easeNone, onComplete:MadeIt}});
X_02_RedWines = X_02_RedWines + 125;


//note callbacks don't need events passed in
function MadeIt():void
{
trace("Made It");
}

please let us know if that works. I haven't yet investigated using both fl.transitions.TweenEvent and our TweenEvents... nor do I recall in any issues in the past. However if I find some info I will let you know.

 

 

Link to comment
Share on other sites

Those constants simply resolve to strings anyway, so you could just plug those in. For example, GreenSock's TweenEvent.COMPLETE is simply "complete", so you can do:

tween.addEventListener("complete", yourFunction);

The same goes for Flash's built-in one. TweenEvent.MOTION_FINISH is just "motionFinish". 

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