AS2 OOP: Changes and Additions
by senocular
Overview
With a new version number, there comes changes.
With Flash MX 2004, not only did the application
itself get a new number, a spiffy 2004 tacked on to the end of its name, but ActionScript
got an upgrade too. The successor to ActionScript is here, ActionScript 2.0.
The most important
development towards OOP is the new ActionScript
2.0. The changes it brings is not so
much functional as it is cosmetic. ActionScript
2.0 adds to the language a new way to define and
manage classes for your Flash movies. All
classes are now written in external text files with an .as file extension
which are then each accessed by Flash and automatically compiled into your swf files when
publishing your movie (depending on whether or
not the movie requires them).
[
flash movie accesses and includes class files
on publish ]
In using such .as files, you'll need to make sure that they are in a location where your Flash movie can access them. This may involve adding directories to the classpath. If you aren't familiar with this process and wish not to get involved right now, just keep class files in the same directory as the Flash movie using them and you should be set.
Other scripting inside
the Flash movie itself still retains the same
form as ActionScript 1.0. The only real change with
ActionScript 2.0 is the syntax in writing classes in those external as files. Some brand new keywords needed in making and
handling classes created for ActionScript 2.0.
These include:
• class
• static
• public
• private
• get
• set
• dynamic
• intrinsic
• extends
• interface
• implements
• import
Each will be covered in greater
detail later on.
Even though ActionScript 2.0 is
directed to programmers with prior programming
backgrounds, learning how to use
it if you're not one will help you become a better programmer on
the whole. But before getting into just how it
works, more changes outside of ActionScript 2.0 need to be addressed - such as those
that come with the new Flash 7 format for .swf files.
|
Editing Note: External .as Files |
Only Flash MX Professional has an
internal ActionScript editor for external files. If you have the non-Pro
version of Flash MX 2004, don't worry about this too much. Basically,
all it does is provide a way to have .as files tabbed in your workspace
and with a copy of the Actions editor filling up the work area (yes,
the normal Actions editor is still there but disabled). As a non-Pro
user, you can use anything from notepad to Dreamweaver to something
like SciTE|Flash
to create your .as files on your own. However, there is a way to use
Flash's Actions editor without Pro. What you can do is make an empty
MovieClip symbol in your Flash movie's library (do not export for
ActionScript) and write scripts in separate layers within that MovieClip.
Name each layer based on the class it contains and use the Actions
editor pin script option to pin each class script to the actions window
in its own tab for quick reference. When finished with the class,
simply use the panel's export option to save it to an external file.
Presto! A free ActionScript 2.0 script editor complete with color
coding and hints. Better yet, all classes are contained within the
.fla file making them much harder to misplace. It may not be the most
elegant solution (exporting is a multi-step process) but it can be
a helpful one. |
|
|