Jump to content
Search Community

Help with TweenLite.from in countdown timer

AndyM test
Moderator Tag

Recommended Posts

Hi all,

 

Sorry if this is a basic question, but I am new to ActionScript (v3) and I'm just going round in circles here.

 

I have a countdown timer script that I am wanting to use "TweenLite.from" on. But the output is blank.

 

Anyone have any idea what's wrong?

 

Any help is appreciated.

 

addEventListener(Event.ENTER_FRAME, loop);

function loop(e:Event):void
{
var nowDate:Date = new Date();
var ms:Number = targetDate.getTime() - nowDate.getTime();
var sec:Number = Math.floor(ms/1000);
var min:Number = Math.floor(sec/60);
var hr:Number = Math.floor(min/60);
var day:Number = Math.floor(hr/24);

// Normalise the values
// See http://layersmagazine.com/build-a-simple-countdown-timer-in-flash.html
sec = sec % 60;
min = min % 60;
hr = hr % 24;

daytxt.text = day.toString();
hrtxt.text  = (hr < 10) ? "0"+hr.toString() : hr.toString();
mintxt.text = (min < 10) ? "0"+min.toString() : min.toString();
sectxt.text = (sec < 10) ? "0"+sec.toString() : sec.toString();

TweenLite.from(sectxt, 1, {alpha:0});

}

Link to comment
Share on other sites

I'm pretty sure the problem is that your tween is in a function that is an ENTER_FRAME handler

 

let's say your frame rate is 30 frames per second.

 

well that means that 30 times per second you are generating a new tween and constantly re-setting the alpha of your object to 0.

 

the tween has a duration of 1 second, but as soon as it starts to run... it gets overwritten the next time an ENTER_FRAME event fires... 1/30th of a second later.

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