The code for the counter was easy to follow, but I'm stumbling through this next phase. Getting a counter display "images" instead of dynamic text.
One of my mentors gave me the code this way.
I've got a working example, but I messed it up. Can someone explain how to put this together?
Documents
numbers.fla
NumberDocumentClass.as
NumbersView.as
Checked This
- run numbers.fla without doing anything "counter works fine, but no image sprites"
- class names "NumbersView,NumberDocumentClass"
- import classes, import NumbersView; import NumberDocumentClass;
attaching class definition to number_0.jpg in library
5000: The class 'NumberDocumentClass' must subclass
'flash.display.BitmapData' since it is linked to a library symbol of that type.
Runtime Error "after attaching NumbersView.as"
1046: Type was not found or was not a compile-time constant: TimerEvent.
Other Issues "maybe other post" - string and array need setup "sort of understand"
numbers.fla
//"counts to a million with two decimal places"
import flash.events.TimerEvent.*;
var timer:Timer = new Timer(10);
var count:int = 0; //start at -1 if you want the first decimal to be 0<
var fcount:int = 0;
timer.addEventListener(TimerEvent.TIMER, incrementCounter);
timer.start();
function incrementCounter(event:TimerEvent) {
count++;
fcount=int(count*count/10000);//starts out slow... then speeds up
mytext.text = formatCount(fcount);
}
function formatCount(i:int):String {
var fraction:int = i % 100;
var whole:int = i / 100;
return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" + fraction : fraction);
}
NumberDocumentClass.as
package {
import flash.display.Sprite;
import flash.utils.Timer;
import flash.events.TimerEvent;
/**
* ...
* Brightest and Best!
*/
public class NumberDocumentClass extends Sprite {
private var timer:Timer = new Timer(10);
private var count:int = 0;
private var fcount:int = 0;
private var numbers:NumbersView;
public function NumberDocumentClass() {
timer.addEventListener(TimerEvent.TIMER, incrementCounter);
timer.start();
numbers = new NumbersView();
addChild(numbers);
}
function incrementCounter(event:TimerEvent) {
count++;
fcount=int(count*count/10000);//starts out slow... then speeds up
//mytext.text = formatCount(fcount);
numbers.setTime(formatCount(fcount));
}
function formatCount(i:int):String {
//var fraction:int = i % 100;
//var whole:int = i / 100;
return ("000000000" + i).substr(-9, 9);
}
}
}
NumbersView.as
package
{
import flash.display.MovieClip;
/**
* ...
* Brightest and Best!
*/
public class NumbersView extends MovieClip
{
private var _listItems:Array = new Array();
public function NumbersView()
{
trace("POOP");
var item:NumberImage;
for (var i:Number = 0; i < 9; i++) {
item = new NumberImage();
addChild(item);
item.x = i * item.width;
_listItems.push(item);
}
}