Home arrow Flash arrow Page 3 - Flash Hack A Custom Color Transform Class
FLASH

Flash Hack A Custom Color Transform Class


See how to implement a custom color transform class in ActionScript 2.0 using object-oriented programming (OOP) instead of using a procedural timeline-based code. (From the book, Flash Hacks, by Sham Bhangal, O'Reilly Media, 2004, ISBN: 0596006454.)

Author Info:
By: O'Reilly Media
Rating: 4 stars4 stars4 stars4 stars4 stars / 14
October 12, 2004
TABLE OF CONTENTS:
  1. · Flash Hack A Custom Color Transform Class
  2. · Code Listing: A Custom Transform Class
  3. · A Closer Look at the Code
  4. · Constructor Function Transform()
  5. · Enhancing the Custom Class

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
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).

 

Buy the book!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.


blog comments powered by Disqus
FLASH ARTICLES

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials