|
ActionScript 2.0 OOP: Introduction
by senocular
Introduction
Here we are going to cover Object Oriented Programming
(OOP) in Flash 7 with ActionScript 2.0, a new
form of ActionScript introduced in Flash MX 2004.
With any luck you've already gone through the sections
covering
OOP with
ActionScript 1.0. Much of the following will
be based off of that foundation, though it is not all necessary to know in order to continue.
Whereas ActionScript
1.0 was very much like Javascript, with ActionScript
2.0, you have a language based on the ECMAScript
Edition 4 specification which... well, which
is also a specification for Javascript but not
as the Javascript (1.x) you're familiar with today.
The Edition 4 proposal is for Javascript 2 which
has more in common with Java than with current
1.x versions of Javascript. So, really, ActionScript
2.0 is to Java as ActionScript 1.0 is to Javascript
(and if you didn't already know, Java is quite
different from Javascript).
Its important to
note that ActionScript 2.0 is not necessarily
a new language. Rather its a new syntax for implementing
an already existing language - the language of
ActionScript 1.0. In fact, ActionScript 2.0 gets
compiled into ActionScript 1.0 when its added
to a published swf file. It will even work in
Flash Player 6 (target Flash Player 6.0.65.0 for
best optimization). So ActionScript 2.0 is basically
just an extension of ActionScript 1.0 that provides
an alternative syntactical form for creating it.
You're not even required to use it in your Flash 7 movies. You have the
option to stick to ActionScript 1.0 in your publish
settings if you feel more comfortable with it.
The reason ActionScript
2.0 exists is not so much to further extend the
abilities of Flash so much. As already established,
when published, ActionScript 2.0 code is actually
converted into ActionScript 1.0. So why allow
for this perversion of syntax when coding with
ActionScript? Well the real reason is simply to
make Flash easier to use when dealing with OOP
in ActionScript. It's true. Some of you may be
laughing at this thinking, "ActionScript
2.0 is absurdly confusing, and no easier than
ActionScript 1.0!" And this may in fact be
the case, especially to devote Flash users who
primarily deal with ActionScript and ActionScript
alone. However, Macromedia is really trying to
push Flash further as a development platform.
More and more you're hearing about Rich Internet
Applications - Flash's evolution from the
basic "Flash Movie." In doing this,
Macromedia needs to make ActionScript more enticing
to more advanced and experienced programmers...
such as those familiar with Java. For those programmers,
ActionScript is a lot easier to grasp and code
for as its syntax is more familiar to them. And because
ActionScript 2.0 is not a requirement for Flash
7 movies (or should I say "applications"?)
and ActionScript 1.0 is still fully functional
and basically no different than before, veteran Flash users
can still maintain their familiar ActionScript
coding environment if they so desire without even
having to touch ActionScript 2.0. So basically,
the sole purpose of ActionScript 2.0 is to provide
a familiar programming environment to those familiar
with its new coding style; programmers such
as Java programmers.
Is ActionScript 2.0 Right for
You? If you're not a serious Flash developer,
you may never have the need to even touch Actionscript
2.0 with a 2.0 foot pole. There's nothing wrong
with that. Don't feel as if you need to learn
this new syntax just because its new and its there.
I personally rarely use it, and if so, only on
large projects where a lot of organization is
needed. Remember, much of OOP revolves around
organization. ActionScript 2.0 takes organization
for ActionScript OOP to the next level. On the
other hand, even if you don't ever plan on using
it, it still may be a good idea to learn. You
never know when you might need to use it and you
may even pick up some good coding practices in
the process. How hard can it be anyway? If you
already know OOP well enough in ActionScript 1.0,
not too hard at all, and probably even a whole lot easier
if you know Java once you get past the ActionScript annoyances. It may be confusing at first
if not explained correctly, but hopefully, that
will not be a problem here.
In the following
pages, we'll take a look at what's new with Flash
7 and ActionScript 2.0. Basically, what you'll
need to know to get by with programming (specifically
with OOP) in this new era of Flash.
|