Flash Hack A Custom Color Transform Class - A Closer Look at the Code
(Page 3 of 5 )
There’s a lot of code there, so let’s take a closer look. But first, you may wonder why we didn’t add the methods of our custom Transform class to the MovieClip or Color class. In ActionScript 1.0, doing so would have been common and even recommended. But in ActionScript 2.0, the preferred approach in most cases is to create a custom class rather than enhancing existing classes.
If you are not familiar with ActionScript 2.0 syntax, notice theclasskeyword used to define the class. Several variables are declared for the class and its instances, outside of any of the methods within the class. The static properties or class properties, defined with the keywordstatic, are defined once for the class (here, we’ve initialized various common transformation types and the refresh rate at which we want our transitions to work,RATE, is set to 50 milliseconds).
The remaining variables declared without the keywordstaticare instance properties (i.e., each instance of the class maintains its own value for the property). Theprivatekeyword identifies class properties and instance properties that are not to be accessed from outside the class. Variables declared within a method, such asgetTrans, which is declared within applyTransform( ), are local variables. The datatypes for all variables, properties, parameters, and method return types are specified using a colon followed by the datatype, such as:Number.
It is good practice to use a standardized variable-naming convention in all code, but because of the precise structuring and datatyping of OOP code, it is perhaps more important here than in other coding styles. Constant variable names (i.e., our static datatypes) have been defined in UPPERCASE, and non-constants have been defined in so-called “camelCase” (a mixture of upper- and lowercase).
 | If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!
Visit the O'Reilly Network http://www.oreillynet.com for more online content. |
Next: Constructor Function Transform() >>
More Flash Articles
More By O'Reilly Media