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
// single line comment
/* */ block comment
trace("Any String"); // debug statement, shows in *output* window
- String constants are placed in double quotes
- All variable and function names are case sensitive
Conditional Statements
ActionScript uses
C-syntax
if (a == b){
} else if (c <> d) {
}
- Use double equals to compare 2 values - works with numbers and
strings
- The phrase after if must be in parentheses
- Blocks are enclosed in curly braces
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.
a1[i] = 5;
a1[i+1] = "any string";
a1.push("new value"); // Add value without an index
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
Edit / Preferences... / ActionScript / uncheck Automatic indentation
Supposedly, you can modify the keyboard shortcuts ... too bad it doesn't work.
Edit / Keyboard Shortcuts...
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
- Alt-FS (Save)
- Ctrl-Ins (Copy)
- Shift-Ins (Paste)
- The cursor motion keys (arrows, home, end, and the like)
are non-standard - if text is highlighted, the first key
press removes the highlight, the second moves the cursor.
As a result, I am always typing in the wrong place.
Author: Robert Clemenzi -
clemenzi@cpcug.org