ActionScript - Basics

ActionScript is the language used to program Adobe Flash movies. Its basic syntax is similar to C and Java.

Flash CS3 uses ActionScript 3.0.

Basics | Conditional Statements | Arrays | Basic Event Handler | Custom Configuration | Irritations


Basics


Conditional Statements

ActionScript uses C-syntax


Arrays

Arrays are not typed, they can hold any type and each element can hold a different type. Arrays are self expanding (as required). They can start with any number (not just zero or one). Use square brackets.


Basic Event Handler

Events allow a user to interact with your program.
// create an event handler
inv_btn.addEventListener(MouseEvent.CLICK, buttonClickHandler);

function buttonClickHandler(event:MouseEvent):void {
  navigateToURL(new URLRequest("http://www.google.com"));
}
More


Custom Configuration

By default, ActionScript autoindents using a tab character ... displayed as 4 spaces. Of course, this makes your code hard to read in a text editor. (Real programmers never use tabs - they have burned me more than once.) Autoindent is a feature I really like ... but Delphi (and other real programming languages) give you the option of using tabs or spaces. Turn tabs off via Supposedly, you can modify the keyboard shortcuts ... too bad it doesn't work. First, create a copy of the current set (the defaults are write protected), then edit what ever you want. I tried adding Ctrl-Ins (Copy) and Shift-Ins (Paste) to Script Edit Commands, but they never worked.


Irritations

In all Microsoft programs, F2 is used to rename the current selection ... but not in Flash - double click a name to change it. F2 displays the Output window.

For copy and paste - Ctrl-Ins and Shift-Ins do not work in all sections - You must use Ctrl-C and Ctrl-V instead.

MouseEvent has Click and Double click ... but not Right click. I guess this keeps it Mac compatible or something. (Actually, Right click opens the Flash control menu.)

It appears that everything is case sensitive. Note, the "Check Syntax" button does not care about case but, when you run the program, function names can not be found if the case is wrong.

Key strokes that work in Flash (and most other Windows programs) do not work in the ActionScript editor


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