This course is adapted from the book “C++ Primer” by Stanley Lippman.
There are currently 2 versions of Actionscript. Actionscript 1.0 (AS 1.0) is the version that works with Flash MX. Actionscript 2.0 (AS 2.0) is the new language that ships with Flash MX2004. Most items in these tutorials will cover both AS 1 and AS 2. Where there is a difference I will indicate it. Actionscript 1.0 will work with Flash MX2004 but Actionscript 2.0 will not work with Flash MX.
To enter actionscript code, open the Actions window by hitting the F9 key or selecting menu item “Window” – “Actions”, and start writing in that window.
Open the Actions window and type in this code:
What you have done is a simple VARIABLE DECLARATION. You have reserved space in memory where some information/data is to be stored.
Now write this in place of above.:
var myNumber = 10;
You have assigned a value to the variable. i.e. stored the value 10 in the variable myNumber.
The trace( ) function prints whatever is between the parentheses to the output window. It displays the value of the argument of trace. To sequence text and variables in a trace function use “+” to add text to number and variables etc.
trace("some Text " + someVariable);
So, here is our complete script,
var myNumber = 10; trace("The value is " + myNumber);
Now execute or run the script. To execute a script hit the keys “Control + Enter” together, or use menu item “Control” – ” Test Movie”.
After a script is written, the next step is to compile it. Compiling means to write to bytecode that Flash understands. The compiler has 2 jobs:
- error checking – the compiler will examine the script for language correctness or errors.
- Translate what we have to instructions that the machine can understand.