Home arrow Flash arrow Page 4 - 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 - Constructor Function Transform()
(Page 4 of 5 )

Next, notice the constructor function, Transform( ), optional in Action-Script 2.0, which is used to initialize instances of the class. Our constructor accepts the target clip to be used later by other methods of the class. The class then defines several public methods that can be invoked on instances of the class, such as invert( ) and fadeToWhite( ), and private methods that are for internal use only.

Notice in particular the form of the setInterval( ) invocation. In this case, the first parameter passed is an object. We invoke setInterval( ) with the keywordthis, which represents the current object (i.e., the instance of the Transform class on which applyTransform( ) was invoked). The second parameter is the name of the method to invoke onthis, namely"transition"(which must be specified as a string). Thus, at the appropriate time, the Transform.transition( ) method is invoked on the current instance,this. Invoking a method on the current instance ensures that instance properties, such asintervalandcolorObj, are in scope within transition( ). The fourth and fifth parameters passed to setInterval( ),diffTransandduration, are passed as parameters to transition( ), when it is invoked. The transition( ) method performs the specified transform over the specified duration and clears the interval when complete.

To use the code, first instantiate an instance of the Transform class, as follows (wheremyVideo_mcis an existing movie clip whose instance name has been set in the Properties panel):

var transformer:Transform = new Transform(myVideo_mc);

Then, invoke any methods of the class on the object:

transformer.invert(3000); // Invert the colors for 3 seconds transformer.fadeToWhite(2000); // Fade to white over 2 seconds

To clean up when you are done, use:

transformer.die();
delete transformer;

 

 

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