Introducing ActionScript
October 29, 2001
For this tutorial, we are going to begin to dig deeper into the
Flash application. This will involve the introduction of
ActionScript, offering some ideas on what it can be used
for, the fun things that can be created, and an idea of what the
future is going to be like with the scripting language. Flash can
create very visually appealing sites or presentations, but with
the introduction of ActionScript in version 4, the future
suddenly seemed much brighter.
ActionScript is an
object-oriented scripting language that helps to manipulate a
Flash movie. While you will want to know some of the basics of
ActionScript you don't need to understand every possible tool in
order to start developing some scripts. You will quickly become
more familiar with the language and thereby you can learn to
create more complicated scripts and in turn more interactive
Flash movies will result.
Just for a quick overview of what an object-oriented scripting
language is, it means the ability to organize information by
arranging it into groups that are called 'classes'.
Multiple instances of a class are called objects, of which
you can create your own or use the ones that are already defined
inside of the ActionScript. When you create a class, you define
all of the properties and the methods of each object that it in
turn creates. The ActionScript language flows logically by
executing the first statement and continuing in order until it
reaches the final statement or a statement that tells
ActionScript to go somewhere else.
With the introduction of Flash 5 came many new features and
syntax that make it very similar to the JavaScript language. For
the technical individuals that are reading this, ActionScript is
based on the
ECMA-262 (The European Computers Manufacturers Association)
specification, which is an international standard
for
JavaScript. The Flash5ActionScript
Web site has documentation and articles to help you
understand the basics of ActionScript.
However, there are some major differences between the two
languages. ActionScript doesn't support browser specific objects
like document, anchor or
window. It also doesn't completely support all of
the JavaScript predefined objects. Of course the same is true in
reverse. JavaScript doesn't support syntax from ActionScript such
as tellTarget, ifFrameLoaded and
others. ActionScript also doesn't support the Function
constructor, or switch, continue,
try, catch, throw, and
statement labels. The eval action can
only perform variable references. In JavaScript 'undefined' in a
numeric context results in NaN, while in Flash 5 the result is
'0'.
The ActionScript can be entered directly into the panel in the
Expert Mode or, using Standard Mode, the user can choose elements
from a pop-up menu or toolbox, similar to as it was done in
version 4. The language supports five different data types, which
are 'number', 'string',
'Boolean', 'Movie Clip' and
'object'. In version 4 there was the ability to use
'slash' syntax to set properties and methods of an object, but
these are no longer preferred. There is now the 'dot' syntax to
get and set the properties including movie clip instances and
variables. You can also declare local variables that will expire
at the end of an action list or a function call. This obviously
allows you to manage memory better and also reuse variable names.
In version 4 all variables were permanent — meaning even
temporary variables like loop counters remained in the movie
until it actually ended.
You can easily reuse blocks of code in your scripts, as you can
define functions with parameters that will return variables.
There are also predefined objects that allow you to access and
manipulate certain types of information. A few examples include:
- The
Date Object allows Flash to pick up the
date and time information from whatever local computer is running
the Flash file.
- The
Mouse Object can hide the cursor so
that you can actually create a custom cursor inside of the movie
itself. Which could certainly confuse and perhaps frustrate
people on a Web site if the arrow were to disappear.
- The
Math Object contains a full range of
built-in mathematical constants and functions. Such as cos
(Cosine) and atan (Arctangent).
- The
MovieClip Object allows you to
control movie clips using various actions such as
tellTarget, play,
loadMovie or others. You can do this from an
instance name by using the dot syntax (example –
someMovieClip.play()).
- Finally the
Sound Object is something
that you can have fun with and allows you to add sounds to a
movie, even adjust the sounds as it plays. There are ways to
adjust the balance (setPan) and even the volume
(setVolume)!
Conclusion - Page 4
Flash 5 Tutorial: Part 1
Additional Features - Page 2
|