ActionScript 3.0 Design Patterns

(Chris Devlin) #1
The Pleasure of Doing Something Well | 5

The great majority of programming languages today are considered procedural in


that they have the concepts and synta xthat support it. The different versions of


BASIC are procedural, as are languages like ColdFusion, PHP and Perl. However,


C++ is a procedural language, as is ECMAScript (ActionScript 3.0) and Ada, lan-


guages many consider object-oriented. Languages like Java are considered true OOP


languages. Without going into a lot of detail, the reason Java is considered a true


OOP language and the others are not is because the only kind of procedure in Java is


a class method. Its structure forces procedures to be class methods, and doesn’t


allow other procedures to operate outside the class structure.


You might be surprised at how heated a discussion can get when it
comes to a language being an OOP language or not. Two versions of
OOP criteria exist. One is fairly inclusive and allows any language
with certain features that can generate OOP code to be considered
OOP. (ActionScript 3.0 is among those.) The other version has a
restrictive criterion that includes those languages thatonlyallow meth-
ods as procedures to be admitted to the exclusive club of OOP lan-
guages. Both versions have valid points. However, we will sidestep the
issue by not taking a position, but note that both sides agree that you
can create good OOP code with a procedural language.

To make a long story short, this does not mean that the other languages are unable


to generate true OOP programs. Well before Java was even available, developers


were creating OOP programs. Some languages, especially those with the ability to


use class structures and override methods, such as ActionScript 3.0, are more OOP


friendly than others. As ActionScript has matured from a few statements to a true


ECMAScript language, it has become more OOP friendly.


Transition to OOP


Changing from sequential or procedural programming to OOP programming is more


than picking up a language that gives you little choice in the matter, as is the case


with Java. However, certain changes in a language can make it more amenable to


OOP, even if it’s not considered a true OOP language by some criterion. In the fol-


lowing sections, some new features in Flash CS3 provide a summary of relevant


changes to the way ActionScript is used.


MovieClip and Button scripts


For the ActionScript veterans whose introduction to programming was writing little


sequential scripts or procedures using theonstatements associated withMovieClipor


Buttonobjects, you’re probably aware that the latest version of Flash doesn’t allow


script embedded in either.

Free download pdf