Functions in ActionScript
Functions are central in ActionScript. We’ll learn about functions with a few different examples.
To run this ActionScript code, you would typically compile it into a SWF file and then run it in a Flash Player or AIR runtime environment. The output would be:
There are several other features to ActionScript functions. One is the ability to use rest parameters and default parameter values, which we’ll look at next.
Note: ActionScript uses trace()
for console output, which is similar to println()
in other languages. In a real application, you might use a TextField to display output on the screen.
Also, ActionScript requires all code to be inside a class, unlike Go where you can have top-level functions. The Functions
class extends Sprite
, which is a basic display object in the Flash framework.