Jump to content
Search Community

onComplete not registering?

weskokigen test
Moderator Tag

Recommended Posts

So I have an onComplete argument set up on one of my tweens, but it does not seem to be functioning correctly. Instead of calling the onComplete function after the completion of the tween, it calls the function right after the tween has been defined. Please help. Here is the code:

 

function mainMouseClickF(event:MouseEvent):void{
for(var i:int = 0; i<3; i++){
	if (event.target.name==buttons[i].name){
		if (window.alpha==0){
			openWindow(i,1);
		}
		if (window.alpha==1){
			openWindow(i,2);
        }
     }
  }
}
function openWindow(i:int, k:int):void{
if (k==1){
	switch(i){
		case 0:
			trace("case0");
			TweenLite.to(window, 0.5, {alpha:1, height:windowHeight});
			break;
		case 1:
			trace("case1");
			TweenLite.to(window, 0.5, {alpha:1, height:windowHeight});
			break;
		case 2:
			trace("case2");
			TweenLite.to(window, 0.5, {alpha:1, height:windowHeight});
			break;
	}
} else if (k==2){
	TweenLite.to(window,0.1,{alpha:0,height:1, onComplete:newWindow(i)});
}
}
function newWindow(i:int):void{
trace("complete");
openWindow(i,1);
}

 

Sorry for the long code, but that's the only way one can diagnose the problem. I just don't understand why the onComplete function is being called right when I activate the tween. :( :( :(

Link to comment
Share on other sites

by putting the () parenthesis afte the function name you are telling the function to run as soon as the line of code is executed.

what you want to do is provide a reference to the function by name

 

BAD

TweenLite.to(window,0.1,{alpha:0,height:1, onComplete:newWindow(i)});

 

GOOD

TweenLite.to(window,0.1,{alpha:0,height:1, onComplete:newWindow, onCompleteParams:});

 

all arguments for the onComplete get passed in via an array in onCompleteParams.

 

that should do it.

 

C

Link to comment
Share on other sites

TweenLite.to(window,0.1,{alpha:0,height:1, onComplete:newWindow, onCompleteParams:});

 

Actually this worked fine at first, but now I'm getting this error:

 

TypeError: Error #1006: apply is not a function.

at com.greensock.core::TweenCore/complete()

at com.greensock::TweenLite/renderTime()

at com.greensock.core::SimpleTimeline/renderTime()

at com.greensock::TweenLite$/updateAll()

 

When I debugged, the error originated at this line of code in TweenCore.as:

 

this.vars.onComplete.apply(null, this.vars.onCompleteParams);

 

Do you have any idea what's going on? Thanks in advance

Link to comment
Share on other sites

That just means that newWindow isn't a function. It must be null or some other type of object. So make sure you're passing a function to the onComplete and you'll be good to go.

 

I don't mean to be pestering but I swear it is. If you read my original posted code you'll see that function newWindow(i:int):void is indeed a defined function. :shock: What am I doing wrong? :o

Link to comment
Share on other sites

You must either still be putting the parenthesis on the end of your newWindow reference (which would literally call the method and return void) or there's something else going on in your code. I can tell you for sure that the error you mentioned points to your newWindow reference NOT being a function. That doesn't mean that you don't have a function called newWindow anywhere - it just means that the WAY you're referencing it when you pass it as the onComplete isn't correct. Do you literally have it set up like onComplete:newWindow and NOT onComplete:newWindow() or onComplete:newWindow(i)?

 

It would be SUPER helpful if you posted a very simple FLA that can be published on our end and clearly reproduces the issue.

Link to comment
Share on other sites

I actuallly set a public variable and it's now working. I'm not sure what the problem was, but I think this way is fine. Thanks for the responses though :D

 

I can probably upload an FLA, but it would be kind of complicated. I'll just use a public variable for now.

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