Difference between empty string and zero value

Type comparisons between text field string values and integers can be bothersome as an empty string would trace as 0. Undeclared integers always default to zero.

textfield.text = "";
trace(int(textfield.text)); // 0

If you need to check whether a textfield is empty or if it contains the number zero, use a boolean.

if(Boolean(textfield.text)) {
// textfield contains some input
if(textfield.text == "0") {
// textfield contains the zero character
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">