Understanding Macromedia Flash 8 ActionScript 2: Basic Techniques for Creatives

Chapter 6: Transitioning From AS1 Classes to AS2 Classes

Classes in Actionscript 1

In ActionScript 1, it was possible to define and use classes. The code was awkward but it worked well and allowed for a dramatic improvement in the organization of application code. For anyone who mastered ActionScript 1 classes, the transition to ActionScript 2 will be easy.

The SimpleSquareAS1 Class

Listing 6.1 shows a class definition in ActionScript 1 style for a class called SimpleSquareAS1. It is based on the mySquare( ) function from Chapter 5. The initial function definition SimpleSquareAS1 serves as the main class definition and the "constructor". It initializes the variables which will serve as the class's "properties". In Chapter 7, the anatomy of a class is discussed in detail and these terms are explained. For now, the important thing to note is that the constructor function does very little work. The actual drawing of the square happens in a function called:

SimpleSquareAS1.prototype.draw
Listing 6.1: An ActionScript 1 class definition
// Constructor Method<b class="bold">function</b> SimpleSquareAS1 (x:Number, y:Number, size:Number,                                    target:MovieClip) {  // Properties  coords = <b class="bold">new</b> Object() ;  coords.x = x;  coords.y = y;  this.size = size;  movieClipTarget = target;  <b class="bold">var</b> depth:Number = movieClipTarget.getNextHighestDepth() ;  name = "mySquare_" + depth;  mc = movieClipTarget.createEmptyMovieClip(name, depth);<a name="227"></a><a...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Automatic Identification Systems (AIS)
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.