Flash ActionScript 3 passing a number to a dynamic text field

In my scene, I have a dynamic text box (instance name = life).

In my ActionScript, I created a numerical variable called livesnum. And then under this, I set the value of the text fields as 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.text = livesnum;

How would I achieve setting a text field as a numeric value to a variable?

+3
source share
1 answer

Use the function toString():

lives.text=livesnum.toString()

or use listing String():

lives.text=String(livesnum);
+4
source

Source: https://habr.com/ru/post/1728468/


All Articles