Number Parsing in ActionScript
In ActionScript, parsing numbers from strings is a common task. Here’s how to do it:
In ActionScript, we use built-in functions for number parsing:
parseFloat()
is used to parse floating-point numbers.parseInt()
is used to parse integers. It can also parse hexadecimal numbers when specifying the radix (base) as 16.uint()
is used to parse unsigned integers.int()
is a convenience function for parsing integers.
Unlike some other languages, ActionScript doesn’t have separate functions for parsing different integer sizes. The int
type is always 32-bit, and uint
is used for unsigned 32-bit integers.
To handle parsing errors, we use a try-catch block. If the parsing fails, an error will be thrown.
To run this code, you would typically compile it into a SWF file and run it in a Flash Player or AIR runtime environment. The output would be displayed in a TextField on the stage.
Next, we’ll look at another common parsing task: URLs.