skips nines in counter object, AS3
- by VideoDnd
It's not that noticeable at first, but my counter skips over to zero and ignores the nines. How can I get my counter to not skip over the nines?
my FLA
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
var timer:Timer;
var count:int = 0;
var fcount:int = 0;
var numbers:NumbersView;
trace("-----new NumberDocument created");
timer = new Timer(10);
timer.addEventListener(TimerEvent.TIMER, incrementCounter);
timer.start();
numbers = new NumbersView();
addChild(numbers);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
//addEventListener(Event.ADDED_TO_STAGE, traceMeOut);
function incrementCounter(event:TimerEvent)
{
count++;
fcount=int(count*count/1000);
}
function formatCount(i:int):String
{
return ("000000000" + i).substr(-9, 9);
}
function enterFrameHandler(e:Event):void
{
numbers.setTime(formatCount(fcount));
}
function traceMeOut()
{
trace("-----Im here on stage!");
}
NumbersView.as
//NumbersView.as - Your Document Class
package {
import flash.display.MovieClip;
public class NumbersView extends MovieClip {
private var _listItems:Array;
private const numHeight:int = 120;
public function NumbersView()
{
_listItems = new Array();
var item:NumberImage;
for (var i:Number = 0; i < 9; i++) {
item = new NumberImage();
addChild(item);
item.x = i * item.width;
_listItems.push(item);
}
setTime('123456789');
}
public function setTime($number:String):void {
var nums:Array = $number.split("");
trace(nums);
for (var i:Number = 0; i < nums.length; i++) {
_listItems[i].start( int(nums[i]) );
}
}
}
}
Variation of NumbersView.as with Tweener
//...SNIPPET
public function setTime($number:String):void {
var nums:Array = $number.split("");
for (var i:Number = 0; i < nums.length; i++) {
if (nums[i] == previousNums[i]) continue;
Tweener.removeTweens(_listItems[i]);
var nuNum:int = int(nums[i]);
var nuY:int = nuNum == 0 ? 0 : (nuNum - 1) * -numHeight;
trace("nuY = " + nuY);
trace("cY = " + _listItems[i].y);
Tweener.addTween(_listItems[i], { y:nuY, time:0 } );
}
previousNums = nums;
}
Variation of NumbersView.as that doesn't skip 9, but resets from bottom every count
//...SNIPPET
public function setTime($number:String):void {
var nums:Array = $number.split("");
for (var i:Number = 0; i < nums.length; i++) {
if (nums[i] == previousNums[i]) continue;
Tweener.removeTweens(_listItems[i]);
var newY:int = int(nums[i]) * -numHeight;
if (_listItems[i].y < 0) _listItems[i].y = numHeight;
Tweener.addTween(_listItems[i], { y:newY, time:3 } );
}
previousNums = nums;
}
PUBLIC CLASS extends MovieClip
place 'NumbersView.as' in same directory
CLASS
Library/'right-click' Properties/Class:NumberImage
SYMBOL
number column 70x1080
numbers 70x120
TWEENER
caurina folder in local directory