DS HomeDev Shed | ASP Free | Dev Articles | Scripts | Dev Hardware | Dev Archives | SEO Chat | Dev Mechanic | Web Hosting
      Flash
igrep Developer Search
Home arrow Flash arrow Flash Hack A Custom Color Transform Class
 
igrep Developer Search
  ADO.NET  
  Apache  
  ASP  
  ASP.NET  
  C#  
  C++  
  ColdFusion  
  COM/COM+  
  Delphi/Kylix  
  Design Usability  
  Development Cycles  
  DHTML  
  Embedded Tools  
  Flash  
  Graphic Design  
  HTML  
  IIS  
  Interviews  
  Java  
  JavaScript  
  MySQL  
  Oracle  
  Photoshop  
  PHP  
  Reviews  
  SQL  
  SQL Server  
  Style Sheets  
  VB.Net  
  Visual Basic  
  Web Authoring  
  Web Services  
  Web Standards  
  XML  
  Developer Forums  
  Forums Archive  
  Get Daily Updates  
  Plug In PDF Mag.  
  Developer Updates  
  Free Website Content  
  Weekly Newsletter  
  Web Hosting
 
  ASP Web Hosting
 
  ASP.NET Web Hosting  
  Budget Hosting  
  Coldfusion  
  Colocation  
  Dedicated Servers
 
  E-Commerce Hosting  
  Linux Web Hosting
 
  Managed Hosting  
  Reseller Web Hosting
 
  Shared Hosting  
  Small Business Hosting
 
  Virtual Private Servers
 
  Windows Web Hosting
 
  Articles:  
Blogs:  
  Forums:  
  Blog History  
  Article Discussion  
  Games  
  Hardware  
  How Tos  
  Law  
  Microsoft  
  Open Source  
  Security  
  SEO  
  Software  
  Technology News  
  Web Hosting  
  Wow  
  Past Technology News
  Apress Books
  Write For Us Get Paid  
  Request Media Kit
  Contact Us  
  Site Map  

Flash


Flash Hack A Custom Color Transform Class
Contributed by O'Reilly Media
Article Rating:starstarstarstarstar / 6
2004-10-12
Poor Best
[ Send Me Similar Content When Posted ]
 
[ Add Developer Shed Headlines To Your Site ]

Discuss This Article
DISCUSS
Developer Newsletter
NEWS
E-mail This Article
SEND
Print This Article
PRINT
PDF Version
PDF
 

Article Index:

  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
  6. Search For More Articles!
  7. Author Terms
 
 
Flash Hack A Custom Color Transform Class - Code Listing: A Custom Transform Class
( Page 2 of 5 )

Although we can’t give a full course on OOP and ActionScript 2.0 here, this custom color transform class can be used even if you don’t understand OOP. And we’ll examine several aspects of the code after the code listing.

Here is our object-oriented version, implemented as a custom Transform class, which must be stored in an external Transform.as file:

// This ActionScript 2.0 code must go in an external Transform.as file
class Transform {
  // NEG_TRANS inverts the color values.
  // NEUTRAL_TRANS resets the color values.
  // BLACK_TRANS sets the color values to black.
  // WHITE_TRANS sets the color values to white.
  // RATE sets the rate the effects will run at in ms.
private static var NEG_TRANS:Object = {ra:-100, rb:255,
           ga:-100, gb:255, ba:-100, bb:255, aa:100, ab:0};
private static var NEUTRAL_TRANS:Object = {ra:100, rb:0,
           ga:100, gb:0, ba:100, bb:0, aa:100, ab:0};

private static var BLACK_TRANS:Object = {ra:100, rb:-255,
          ga:100, gb:-255, ba:100, bb:-255, aa:100, ab:0};
private static var WHITE_TRANS:Object = {ra:100, rb:255,
          ga:100, gb:255, ba:100, bb:255, aa:100, ab:0};
private static var RATE:Number = 50;

private var interval:Number;
private var startTime:Number;
private var colorObj:Color;
// Constructor accepts target clip to which to apply transforms
public function Transform(targetClip:MovieClip) {
 colorObj = new Color(targetClip);
}

// Inverts the color values
public function invert(duration:Number):Void {
 applyTransform(NEG_TRANS, duration);
}

// Resets the color to the default values set in the authoring tool
public function reset(duration:Number):Void {
 applyTransform(NEUTRAL_TRANS, duration);
}

// Performs a fade to black over specified duration in ms
public function fadeToBlack(duration:Number):Void {
 applyTransform(BLACK_TRANS, duration);
}

// Performs a fade to white over specified duration in ms
public function fadeToWhite(duration:Number):Void {
 applyTransform(WHITE_TRANS, duration);
}

// Function to initiate a fade and set up an interval to
// complete it over time.
private function applyTransform(transObject:Object,
                               duration:Number):Void {
var getTrans:Object = colorObj.getTransform( );
var diffTrans:Object = new Object( );
startTime = getTimer( );
for (var i in transObject) {
diffTrans[i] = (transObject[i] - getTrans[i]) / (duration / RATE);
}
// Use the form of setInterval( ) that invokes a method of an object,
// so that instance properties are in scope (the object is this).
// First parameter is the object (this) on which to invoke the
// method specified by the second parameter (in this case
// "transition", which must be passed as a string).
// Third parameter is interval duration in ms.
// Fourth, fifth, and sixth parameters get passed to transition( )
interval = setInterval(this, "transition", RATE, transObject, diffTrans,
duration);
}

// This method applies each step of the color transformation.
private function transition(transObject:Object, diffTrans:Object,
duration:Number):Void {
  var getTrans:Object = colorObj.getTransform( );
  for (var i in diffTrans) {
    getTrans[i] += diffTrans[i];
  }
  colorObj.setTransform(getTrans);
  if (getTimer( ) - startTime > duration) {
    // Complete the final step in the transition
    colorObj.setTransform(transObject);
    // Clear the interval to stop the effect
    clearInterval(interval);
  }
  // Force the screen to refresh between frames
  updateAfterEvent( );
 }
 public function die( ):Void {
   // Perform any cleanup code here
 }
}

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.


DISCUSS ARTICLE

GET NEWSLETTER

SEND ARTICLE

PRINT VERSION

PDF VERSION


   

Flash Articles


- Basic Flash ActionScript for Designers
- Working with external data in Flash
- Working with Text and HTML in Flash
- Introduction to Flex
- What is ActionScript?
- The Power of LoadVars Object
- Making an MP3/FLV Player with Flash MX 2004 ...
- Using Function: The Beginner's Nightmare
- Flash Hack A Custom Color Transform Class
- Create a Flash Speech Synthesizer
- Undocumented ActionScript Flash Hack
- Object-oriented ActionScript
- Flash Hacks: Simulate 3D and Add a Vector Ed...
- ActionScript 2.0 Overview
- A Simple XML-Based Searchable Database


More by O'Reilly Media


- Introducing JavaServer Faces
- Java in Review
- Generics of Java 1.5 Tiger
- What`s New in Java 1.5 Tiger?
- XML as a Publishing Technology
- Flash Hack A Custom Color Transform Class
- Create a Flash Speech Synthesizer
- Undocumented ActionScript Flash Hack
- Object-oriented ActionScript
- Flash Hacks: Simulate 3D and Add a Vector Ed...
- ActionScript 2.0 Overview


Blog Banter


Pentax, Samsung unit in digital camera tie-up 9:06 am EST

Japan's Pentax Corp. (7750.T) said on Wednesday it has tied up with a unit of South Korea's Samsung Electronics (005930.KS) to jointly develop digital single lens reflex (SLR) cameras, aiming to po... More | Discuss
EU Pushes for Online Music Copyright 9:06 am EST

The European Union called on Europe's music industry Wednesday to create EU-wide copyright licenses for online music, saying this would boost demand for legal downloads. More | Discuss
Apple's record fourth quarter called 'disappointing' 8:06 am EST

Apple Computer reported a record fourth quarter, but that wasn't enough for Wall Street because Apple's results weren't as robust as some analyst estimates. Apple had its best quarter ever for iPod sa... More | Discuss
Nokia launches new corporate phone line-up 8:06 am EST

Mobile phone giant Nokia said on Wednesday it was launching three new mobile devices for business users, to hit the shelves in the first quarter of next year. More | Discuss
London bomb survivor sets up victim Web site 8:06 am EST

Canadian Peter Zimonjic had never seen a corpse before being caught up in the London suicide bomb attacks that killed 52 people in July. More | Discuss
Past Technology News

Scripts.com
Dev Articles - Your Multi-Platform Development Source Dev Articles
Get This For Your Site!
 
» JavaScript Remote Scripting: Fetching Server Data with the DOM in: JavaScript
 
» Exception Handling in JavaScript: Addressing Browser Incompatibilities in: JavaScript
 
» Temporary Variables: Chasing Temporaries Away in: C++
 
Website Marketing
Dev Shed - The Open Source Web Development Site Dev Shed
Get This For Your Site!
 
» Caching Result Sets in PHP: A Content-Change Triggered Caching System in: PHP
 
» Generic Architecture for Caching Table Data: Supercharge Your PL/SQL Applications in: Oracle
 
» Caching Result Sets in PHP: The Barebones of a Caching Class in: PHP
 
Developer Newsletter
ASP Free - Your Source For ASP Source Code and More... ASP Free
Get This For Your Site!
 
» IIS 6.0, Getting Information Using WMI in: IIS
 
» Understanding and Creating an Access Project in: Microsoft Access
 
» ASP.NET Custom Server Controls: Dynamically Expandable Round Cornered Button in: ASP.NET
 
$7.95/mo. Web Hosting
Dev Hardware - Your Home for Hardware Resources Dev Hardware
Get This For Your Site!
 
» DARPA’s Grand Challenge: A Real Race This Time! in: Opinions
 
» Swiftech MCW6002-64 and MCW50+T Waterblocks in: PC Cooling
 
» Modding 101: The Basics in: Computer Cases
 
Free Programming Scripts
SEO Chat - Search Engine Optimization SEO Chat
Get This For Your Site!
 
» Search Engine Optimization and CSS in: Search Optimization
 
» Google-Sun Alliance: Big Bore or Big News? in: Search Engine News
 
» Improve Your Rankings with a Sitemap That Works: The HTML in: Search Optimization
 
WEBSITE HOSTING
Dev Mechanic - Webmaster Tools, Developer Tools, Programming Tools Dev Mechanic
Get This For Your Site!
 
» Relax Your Clients And Improve Your Sales! in: Online Business Help
 
» Developing an eBook as a Marketing Tool. Simple and Easy! in: Website Marketing
 
» How Blogs And RSS Boost Your Search Engine Visibility in: Blog Help
 
#1 BEST WEB HOSTING 2004
Web Hosters - Find Webhosting Now! Web Hosters
Get This For Your Site!
 
» Keeping Connected to Your Web Hosting Business in: Web Hosting Articles
 
» Web Hosting Community Rallies around New Orleans in: Web Hosting News
 
» Heroic Web Hosting: DirectNIC vs. Katrina in: Web Hosting News
 
Coldfusion
Developer Shed Blog - Technical Professionals Discuss Todays Topics... Dev Blog
Get This For Your Site!
 
» Apple`s record fourth quarter called `disappointing` - Discuss
 
» Nokia launches new corporate phone line-up - Discuss
 
» London bomb survivor sets up victim Web site - Discuss
 
WEBSITE DESIGN
                        Add Mozilla Sidebar | Bookmark this site | WAP support for your phone | Klip for KlipFolio
Dev Shed Forums | ASP Free Forums | Dev Articles Forums | Dev Hardware Forums | SEO Chat Forums | Dev Archives Forums
 
 
© 2001-2005. All rights reserved. (Privacy Policy) Dev Articles Cluster 5 hosted by HostwaySupport
 

Generated in 0.559330 sec.