开发者

flash actionscript 3.0 how to display integers?

im new to flash - actionscript 3.0. I have creat开发者_如何学JAVAed a text and i am able to set a string by doing txt.text = "something". My problem is, i want to display an integer instead of a string, how is this possible?

thank you.


ActionScript is generally very forgiving when something needs to be cast to string and it will often do it for you. This should work:

var a:int = 1;
txt.text = a; // Now that I think of it, I forget if AS3 has issues with this. 
              // AS2 does not

If concatenating to a string, however, I recommend strict casting, as that will avoid an accidental NaN:

var a:int = 1;
var str:String = "foo";
txt.text = str + String( a ); // now "foo1"

Remember too, if adding to the end of a textfield's text (instead of assigning it), use appendText.


var myNumber:Number = 2;
txt.text = myNumber.valueOf(); //or txt.text = new String(2);


It sounds like you want to use a NumberFormatter. Here's Adobe's example to get you started.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜