2

如何使用计数器触发精灵?需要一个例子或想法来工作。

我希望数字值加载精灵。计数器的值转到文本字段。我希望每个数字值都有一个“if”条件来播放相应数字的精灵。

替代文字 http://www.ashcraftband.com/myspace/videodnd/icon_7.jpg

愚蠢的例子
//计数器在文本字段中播放图片而不是播放数字

详细示例
//如果大于 0 且小于 2,则播放 1 ==> ONE DISPLAYS ON SCREEN

比较
- 变量数据显示“像 Flash 音乐可视化”
- 数据是一个计数器

它是如何工作
的 -loaders 从计数器
-9 目标“9 个数字空间”接收数字值 -
添加和删除子
项 -允许计数器看起来像任何东西

替代文字 http://www.ashcraftband.com/myspace/videodnd/icon-3.jpg

我想使用的计数器

//"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);   
} 
4

2 回答 2

1

你想做这样的事情吗?

http://shaneberry.net/numbers/

如果是这样,我可以为源提供链接。

于 2010-02-11T19:53:42.657 回答
0

如果我正确理解您的问题,您需要一个屏幕计数器,该计数器对计数的每个数字使用不同的图像/精灵。

您可以将 formatCount 修改为如下所示:

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
}
于 2010-02-11T19:30:45.137 回答