Flash Actionscript 3 passing a number to dynamic text field
On my stage I have a dynamic text field (instance name = lives).
In my actionscript I have created a number variable called livesnum. And then beneath that I'm setting the textfields value to be the livesnum variable but I get the following error:
1067: Implicit coercion of a value of type Number to an unrelated type String.
My actionscript is as follows :
var livesnum:Number = 4; //Amount of lives
lives.t开发者_Python百科ext = livesnum;
How would I achieve setting the textfield as the numeric value of the variable?
Use toString
() function:
lives.text=livesnum.toString()
or use a cast String()
:
lives.text=String(livesnum);
精彩评论