ActionScript - Simple Programs

You'd think that *Hello World* would be simple ....

Writing Code | Hello World | A Simple Button | Debug Assistance | Comments


Writing Code

Code is entered via the Actions frame ... open it via In ActionScript3, code can only be added to a layer. It is considered good practice to create a code layer and to attach all of the code to frame 1 of that layer.

It is also possible to create a separate script file and add it to the library. This is the preferred method for code that will be used with multiple projects.


Hello World - no button

In a new project In order to add code The tab at the bottom of the Actions frame will tell you where the code will be stored - you want code : 1.

In the Actions frame, click Script Assist - this will provide some help. Since you are just starting, I suggest using the library tree in the upper left of the Actions frame. Navigate to and double click

This will add 2 lines of code to the script The first line includes the necessary library, the second is a partial line of code, change the code to Test the form (press Ctrl-Enter) - the new text should be displayed.

The following code performs the same function using a variable ... this is useful because it enables good context sensitive help when you type s dot.


A Simple Button

Code placed in the script is executed immediately. In order to control when the code is run, it needs to be placed in subroutines and called when some event occurs. Using the project above


Help

The popup help for addEventListener is a little confusing type is a case sensitive string. For mouse click, you can use either of these The help file suggests using the property because the compiler will catch any errors ... if you mistype the case sensitive strings, then the program may fail in weird ways.

The available events are not very easy to find - these apply to MouseEvent


Debug Assistance

Sometimes it is useful to indicate what is happening while the code is running.

The following can be used to send any string to the Output panel.

Actually, trace can accept multiple arguments, of most types (not just strings), separated by commas.


Comments

This language is object oriented, but the user interface is fairly weak. To write code Naming conventions


Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Languages / ActionScript / SimplePrograms.html