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.
精彩评论