Flash Hack A Custom Color Transform Class
(Page 1 of 5 )
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.)
HACK 10: A Custom Color Transform Class
Create a custom class to perform color transformations.
We saw in the preceding two hacks that there are several common color transformations [Hack #8] you may want to perform on a target clip. Furthermore, we saw that this requires a bit of housekeeping, including setting up timers and callbacks [Hack #9]. The nature of the task suggests that it is a great candidate to be implemented as a custom class. The class can take care of all the grunt work, allowing us to perform a color transformation or fade using a few simple calls to the custom class’s methods.
In this hack, we implement a custom color transform class in ActionScript 2.0 using object-oriented programming (OOP) instead of the procedural timeline-based code seen in the preceding hacks.
An Object-Oriented Transformation
Using ActionScript 2.0 requires Flash MX 2004 or Flash MX Professional 2004. You must set the ActionScript Version to ActionScript 2.0 under the Flash tab in the File -> Publish Settings dialog box. Furthermore, the custom Transform class we’ll develop must be placed in an external plain-text file named Transform.as (both the capitalization of the name and the .as extension are mandatory).
You can create and edit such a file in Flash MX Professional 2004 if you select File -> New -> ActionScript File. If using Flash MX 2004, you’ll need an external text editor [Hack #74]. The .as file should be placed in the same folder as the .fla file that makes use of the Transform class. For many more details on ActionScript 2.0 classes and object-oriented development, see Essential ActionScript 2.0 by Colin Moock (O’Reilly). [Editor's note: Dev Articles featured the following from Colin Moock's book: Object-oriented ActionScript, and ActionScript 2.0 Overview.]
 | 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: Code Listing: A Custom Transform Class >>
More Flash Articles
More By O'Reilly Media