Jump to content
Search Community

onComplete argument type in AS3?

inorganik test
Moderator Tag

Recommended Posts

Hi, I love using TweenLite, especially in functions, for instance:

 

function alphUp (mc:MovieClip, del:Number):void {
TweenLite.to(mc, 1, {delay:del, alpha:1});
}

 

However, if I want to add an "onComplete" and "onCompleteParams" to it, how do I identify the arguments properly in the function? Also, if I want to call the function without the onComplete, what can I do to avoid getting the "missing arguments" error?

 

Thanks in advance!

Link to comment
Share on other sites

if I want to add an "onComplete" and "onCompleteParams" to it, how do I identify the arguments properly in the function?

 

The onComplete refers to the function you want to call, and onCompleteParams is an Array that has all the parameters in it (in order), like if you wanted to tween two objects to a new random position every 5 seconds over and over again, you'd do:

 

function randomTween(mc:MovieClip, delay:Number):void {
  TweenLite.to(mc, 1, {delay:delay, x:Math.random() * stage.stageWidth, y:Math.random() * stage.stageHeight, onComplete:randomTween, onCompleteParams:[mc, 5]});
}
randomTween(mc1);
randomTween(mc2);

 

Also, if I want to call the function without the onComplete, what can I do to avoid getting the "missing arguments" error?

I don't understand what you mean. Please post the code that's generating the error. Did you mean to say "...without the onCompleteParams"? If so, you'd need to build your function so that it doesn't require any parameters (use defaults) like:

 

function myFunction(param1:Number=0, param3:String=""):void {
   //code here.
}

Link to comment
Share on other sites

I should've specified, I want the function's arguments to include the values for onComplete and onCompleteParams. So I'm asking what would that look like? Basically, fill in the blanks below:

 

function alphDown (mc:MovieClip, func:_______, params:_______):void {
TweenLite.to(mc, .5, {alpha:0, onComplete:func, onCompleteParams:[params]});
}

 

Also, as I said, I want to be able to execute that function sometimes without the onComplete. I've found however that when you execute a function in AS3 with missing arguments, you get the error I mentioned. So would I pass "null"? Or just write a separate function w/o the onComplete?

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