Jump to content
Search Community

function doesn't run in tweenMax delayedCall

Xristi test
Moderator Tag

Recommended Posts

Hi,

 

I don't imagine this is a terribly difficult problem to solve - perhaps I can't see the forest through the trees. I have the following:

 

TweenMax.delayedCall(1, countDown);

 

function countDown():void

{
     unitSec = int(inputTextFieldsArray[0].text);
     unitSec--;
     inputTextFieldsArray[0].text = String(unitSec);

}

 

if I append parentheses to the countDown function, the function is called and it counts down from whatever number is in the textfield like it's supposed to. Unfortunately, it doesn't pay any attention to the 1 second delay. Without the parentheses the function doesn't fire. Thank you for any help you can give me! The documentation shows no parentheses...

Link to comment
Share on other sites

hmm, from what you have provided it appears the TweenMax part is correct.

I modified and tested your code as follows:

 

TweenMax.delayedCall(1, countDown);

function countDown():void
{
trace("countDown function called");
     
/*
unitSec = int(inputTextFieldsArray[0].text);
     unitSec--;
     inputTextFieldsArray[0].text = String(unitSec);
*/
}

 

 

Worked perfectly. After 1 second the trace() fired.

 

Does it work for you? If not, please feel free to zip and upload a very simple fla.

 

And, yes, you should not have the parenthesis after countDown inside the delayedCall()

countDown() // means call the function now
countDown // a reference to the function that should be called when the delay expires
Link to comment
Share on other sites

Hi Carl,

 

Yes, what you have worked. However, I am building a count down timer so it needs to delay the one second each time the delayed call is made. I have attached a small zipped fla file. The program goes to the delayed call function after one second, but then accesses that function without regard to the delay. Is there another code bit that has to go inside the parentheses so that the trace statement is printed nine times with a one second interval between each printing?

CountDownTrial.zip

Link to comment
Share on other sites

Your code in your fla was a bit different than what you provided earlier.

 

try this

 

import  com.greensock.TweenMax;
import flash.events.MouseEvent;


var i:int = int(numText_txt.text);


startButton_btn.addEventListener(MouseEvent.CLICK, startCountDown);


function startCountDown(e:MouseEvent):void {
  //wait 1 second after click
TweenMax.delayedCall(1, countDown); 


}


function countDown():void
{
trace(i);
if(i > 0) {
 i--;
 numText_txt.text = String(i);
 TweenMax.delayedCall(1, countDown); // call countDown again 1 second from now


} else {
trace("done"); 
}
}

Your previous code using the while loop created 9 delayedCalls all at once that called the same function at the same time.

function startCountDown(event:MouseEvent):void
{
while(i > 0)
{
trace(i) // all happens instantly on the same frame
TweenMax.delayedCall(1, countDown);
i--;
}
}
Link to comment
Share on other sites

Yes, I tried to make it as bare bones as possible, but still retain what I really wanted to do, as long as I had your help :-) Thank you once again, for your patience and considerable expertise. Your code works great... now on to coding seconds to minutes and minutes to hours.

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