views:

161

answers:

2

How do I use the counter to trigger sprites? Need an example or idea to work from.

I want the number values to load sprites. The value of the counter goes to a text field. I want each number value to have an "if" condition to play a sprite of a corresponding number.

alt text

Dumb example
//counter plays pictures rather than plays numbers in text field

Verbose example
//if more than 0 and less than 2, play 1 ==> ONE DISPLAYS ON SCREEN

Comparison
-variable data display "like Flash music visualization"
-data is a counter instead

How it could work
-loaders receive number values from counter
-9 targets "9 number spaces"
-add and remove child
-allows counter to look like anything

alt text

COUNTER I WANT TO USE

//"counts to a million with two decimal places" <br>
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);   
} 
A: 

If I understand your question correctly, you want an on screen counter that uses a different images/sprites for each digit of the count.

You could modify formatCount to something like this:

var decimal_space:int = 5;  //the amount of space for the"."
var width_of_sprite:int = 16;
var decimal_digits:int = 2;
var whole_digits:int = 7;
var sprites:Array = new Array();

//this will create sprites for the whole digits from left to right
for (var i:int = 0; i < whole_digits; i++) {
  var s:Sprite = new Sprite();
  s.x = i * width_of_sprite + decimal_space;
  sprites.push(s);
  this.addChild(s);
}

//this will create sprites for the decimal digits from left to right
for (var i:int = 0; i < decimal_digits; i++) {
  var s:Sprite = new Sprite();
  s.x = (i + decimal_digits) * width_of_sprite + decimal_space;
  sprites.push(s);
  this.addChild(s);
}

function formatCount(c:int):String {   
  for (var i:int = whole_digits + decimal_digits - 1; i >= 0; i--) {
    redraw_sprite(sprites[i],c % 10);
    c = (c - (c % 10)) / 10;
  }
} 

function redraw_sprite(sprite:Sprite, value:int):void {
  //add code here to redraw each sprite
}
Nathan Villaescusa
I'll noodle on it, this helps with the arguments.
VideoDnd
+2  A: 

Are you looking to do something like this?

http://shaneberry.net/numbers/

If so, I can put a link up for the source.

sberry2A
Yes, that's awesome! That's what I'm after. Please put up the source.
VideoDnd
It looks like something from Metropolis
VideoDnd
source is now available.
sberry2A
That's just awesome. Thanks again
VideoDnd