Transforming the Current Color of a Flash Movie Clip

by Elis Frugalo.

Share
|
Homepage | Submit your article | Contact | TOS
More articles on flash  

You are here: Categories » Computers and technology » Flash

You want to modify a movie clip's color relative to the current color transformation, instead of relative to the author-time color values.

Use the getTransform( ) and setTransform( ) methods of the Color object that targets the movie clip.

The Color.getTransform( ) method returns the transform object last applied to the targeted movie clip. For example, if you had previously applied a transform object that set the movie clip's alpha percentage to 42, getTransform( ) would return an object with the following values:

{ra: 100, rb: 0, ga: 100, gb: 0, ba: 100, bb: 0, aa: 42, ab: 0}

The transform object reflects changes made to a movie clip's color either at authoring time or at runtime. If you modify the color values using the Property inspector at authoring time, those values are indicated in the movie clip's transform object. You can make changes to a movie clip's color at runtime by using the setTransform( ) or setRGB( ) methods of its Color object, and you can adjust the movie clip's _alpha property separately. All runtime changes—not just the changes made using setTransform( )—are reflected in the transform object. If you have not applied any color changes at runtime or authoring time then getTransform( ) returns the following value (a neutral transform object):

{ra: 100, rb: 0, ga: 100, gb: 0, ba: 100, bb: 0, aa: 100, ab: 0}

You can modify the properties of the transform object returned by getTransform( ) and then apply the modifications using setTransform( ):

// Create the Color object.
   my_color = new Color(myMovieClip);
// Get the transform object.
   myTransformObject = my_color.getTransform(  );
// Set the green percentage of all colors within the movie clip to 50% of the current
   // value.
   myTransformObject.ga = 50;
// Apply the transform object.
   my_color.setTransform(myTransformObject);

The preceding example retains the previously applied transform values, with the exception of ga, which is set to 50. You can instead increment or decrement the properties relative to their current values:

// Get the transform object.
   myTransformObject = my_color.getTransform(  );
// Increment the red, green, and blue offsets by 10 to brighten the object's colors.
   myTransformObject.rb += 10;
   myTransformObject.gb += 10;
   myTransformObject.bb += 10;
// Set the transform object.
 my_color.setTransform(myTransformObject);

Transformations applied with setTransform( ) occur relative to the colors in the original movie clip symbol, independent of any previous transformations. In other words, the transformations are not cumulative. We simulated a cumulative transformation by basing the new transformation on the previous values, as returned by getTransform( ).

Leave a comment or ask a question
Total comments: 0

Flash Disclaimer

  • The e-articles directory is not responsible for any and all copyright infringements by writers and authors. If you suspect the information contained by this page for any copyright infringements, please contact us to investigate the issue
Move Clip Rotation - A property like _x and _y is the movie clip property _rotation. The _rotation property accepts a value in degrees. A circle is divided into 360 degrees. The values used by _rotation range f (more...)
Targeting Flash Movie Clips - The simplest way to target a movie clip is to use its name, followed by a dot, followed by the command you want to send. However, there are plenty of other ways to target a movie clip as we (more...)
Using Mathematical Operators in ActionScript - You want to modify something over time, such as the rotation or position of a movie clip. Use the compound assignment operators to change a variable or property in increments. Or, if increm (more...)
How to build an animated button using Flash - Time: 15 Minutes. Difficulty Level: Intermediate Requirements: Flash 8 Assumed Knowledge: Basic action (more...)
Enhancing Standalone Projector - You want to create an enhanced Standalone Projector with features such as borderless playback, custom titles, no Flash menus, and so on. Use a third-party tool such as SWF Studio or SWFKit to c (more...)
Creating Flash Buttons - Buttons are one of the three main types of symbols that you use in Flash. The others are movie clips and graphics. Making a New Button There are many ways to create a button. One (more...)
Bouncing Ball Script - Start a new Flash movie. Create a movie clip that has a ball graphic inside it. You can name the instance of the movie clip, myClip, but our code will not depend on the name of the clip. (more...)
ActionScript: Creating Reusable Code - You want to perform a series of actions at various times without duplicating code unnecessarily throughout your movie. Create a function and then call (i.e., invoke) it by name whenever you (more...)
3D Scaling with ActionScript - Although Flash is not capable of real 3D graphics, the kind seen in popular computer games, you can create the illusion of 3D by using scaling. Scaling an object is a great way to give your (more...)
The Dot Syntax - Something else that you will be seeing a lot of as you learn ActionScript is dot syntax. Dot syntax is a way of grouping objects and functions that is used in many object-oriented programming (more...)

 
free content
    Copyright © 2006 - 2012 e-articles.info.
The texts, articles and tutorials in the directory are property of their respective owners and authors.