Jump to content
Search Community

onComplete Parameters Issue

soupking test
Moderator Tag

Recommended Posts

I'm trying to call a function using onComplete:

 

The problem I'm having is that I need to pass parameters to the class I'm calling. Doing so makes the onComplete useless because it runs automatically thanks to the (). If I don't include the parameters it gives me a #1009.

 

I'm guessing this is a common issue, but couldn't find the answer searching in this forum.

 

Is there a simple solution to this issue?

Link to comment
Share on other sites

Yep, there's a simple solution - you should NOT be putting "()" on the end of your function name when you pass it to TweenLite/Max as an onComplete because the () tells Flash to run it immediately.

 

Let's say you have a function that needs two parameters, a String and a Number:

function myFunction(param1:String, param2:Number):void {
  //code here...
}

 

You can use TweenLite/Max's onCompleteParams feature to pass an array of those parameters which it will feed your function.

 

BAD:

TweenLite.to(mc, 1, {x:100, onComplete:myFunction()}); //don't do this

 

GOOD:

TweenLite.to(mc, 1, {x:100, onComplete:myFunction, onCompleteParams:["param1", 2]});

Link to comment
Share on other sites

Yep, it's the same in AS2. The only difference for AS2 is that if you refer to "this" in the onComplete function, you'll need to define the function's scope using onCompleteScope because AS2 doesn't maintain scope like AS3 does (that has nothing to do with TweenLite/Max specifically). So in AS2, you'd do TweenLite.to(mc, 1, {_x:100, onComplete:myFunction, onCompleteParams:["param1", 2], onCompleteScope:this});

 

If you're having trouble with some particular code, please post a sample FLA that demonstrates the problem. I'm sure we can get it figured out.

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