What says NaN? How is health defined in the _root?
Health says NaN.
code in frame: text.Life = "Health: " + health
the health variable is in the Life text properties.
1 person found this helpful
a textfield's text property is always a string (even if it looks like a number to you). you can cast it as a number, if that's reasonable:
// this will also cause an NaN error if sometextfield.text="hi", for example.
// but if the text property looks like a number to you, flash will handle the conversion without problem.
// and you can then treat _root.health as a number.
but, if you use:
and try something like:
you will always get an NaN error.
Your explanation is not very clear. You should use a variable for the health and a textfield for displaying it as a separate entity. In the _root timeline declare the variable...
var health = 100; // or whatever value it starts at
And if you plan to display the health value in a TextField, then create a TextField and assign it an instance name... let' say you name it "healthTxt" and it also lives in the _root timeline. Then your code should look like...
_root.healthTxt.text = String(_root.health);
and if all of that code happens to be on the _root timeline, get rid of all the unnecessary _root references. You should not make a habit of throwing _root in front of everything in sight. You should only use it if you are not on the _root timeline and have no other means of targeting it.