trigger animation with timer, as3
Posted
by VideoDnd
on Stack Overflow
See other posts from Stack Overflow
or by VideoDnd
Published on 2010-04-23T18:19:50Z
Indexed on
2010/04/23
18:23 UTC
Read the original article
Hit count: 209
flash
|actionscript-3
How do I trigger the animation in sync with my timer?
My timer
and flip animation work, but they are out of sync with each other. I'm lost with the IF ELSE statements. Each time the value of my textfield changes, my number needs to flip. See example.
Example
//IF ELSE FUNCTION
function theFlip(event:TimerEvent):void
{
count++;
if (count < 9)
{
oldcount = count - 1;
}
else
{
count++;
fcount=int(count)
count++;
oldcount = count - 1;
}
}
//Cont...
Complete Code
here's the file
//Timer
var timer:Timer = new Timer(100);
//Integer values
var count:int = 0;
var fcount:int = 0;
var oldcount:int = 0;
//Formatting String
function formatCount(i:int):String {
var fraction:int = i % 100;
var whole:int = i / 100;
return ("00" + whole).substr(-2, 2) + "." + (fraction < 10 ? "0" + fraction : fraction);
}
//Start the timer
timer.start();
timer.addEventListener(TimerEvent.TIMER, theFlip);
//IF ELSE FUNCTION
function theFlip(event:TimerEvent):void
{
count++;
if (count < 9)
{
oldcount = count - 1;
}
else
{
count++;
fcount=int(count)
count++;
oldcount = count - 1;
}
var toText:String = formatCount(fcount);
sec4.digit.text = toText.substr(4, 1);
flip4.flip.digit.text = toText.substr(4, 1);
flip4.gotoAndPlay(2);
sec3.digit.text = toText.substr(3, 1);
flip3.flip.digit.text = toText.substr(3, 1);
flip3.gotoAndPlay(2);
sec1.digit.text = toText.substr(1, 1);
flip1.flip.digit.text = toText.substr(1, 1);
flip1.gotoAndPlay(2);
}
© Stack Overflow or respective owner