Decoding an RGB Value

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 extract the red, green, and blue components from an RGB value returned by Color.getRGB( ).

Use the bitshift right and bitwise AND operators.

You can extract the red, green, and blue components from the single RGB value returned by Color.getRGB( ) using the bitshift right (>>) and bitwise AND (&) operators. You can extract one or more of the colors individually as follows:

// Create the Color object.
   my_color = new Color(myMovieClip);
// Get the current RGB color.
   rgb = my_color.getRGB(  );
// rgb contains an RGB color value in decimal form, such as 14501017 (rosy pink), 
   // which is stored internally as its hex equivalent, such as 0xDD4499.
   red   = (rgb >> 16);
   green = (rgb >> 8) & 0xFF;
   blue  =  rgb & 0xFF;

Although displayed as a decimal number, remember that each color is stored internally in its hexadecimal form: 0xRRGGBB. For example, the color value 14501017 (which is rosy pink) is stored internally as 0xDD4499. In this format, it is easy to see that the red component is DD in hex (221 in decimal), the green component is 44 in hex (68 in decimal), and the blue component is 99 in hex (153 in decimal).

The preceding transformation effectively separates a 24-bit value into its three 8-bit components (the leftmost eight bits represent red, the middle eight bits represent green, and the rightmost eight bits represent blue). The bitshift right operator is used to shift the eight bits of interest to the rightmost position. Using the bitwise AND operator with 0xFF retains the rightmost eight bits only, effectively masking off any unwanted bits on the left.

In practice, it is often easier to use Color.getTransform( )—in which the red, green, and blue components are returned as separate properties of a transform object—to determine a clip's color. Furthermore, getTransform( ) also returns the alpha value for a color, which getRGB( ) does not

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
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...)
Movie Clip Scripts - Movie clip scripts, like button scripts, use handlers. Instead of using the on keyword that button scripts use, we will use the onClipEvent keyword. Here is an example of a movie clip script: (more...)
ActionScript: Generalizing a Function to Enhance Reusability - You want to perform slight variations of an action without having to duplicate multiple lines of code to accommodate the minor differences. Add parameters to your function to make it flexib (more...)
Scaling a Flash Movie - You want to control how a movie fits in the Player, including the scaling. Use the Stage.scaleMode property. The Flash Player defaults to a scale mode of "showAll" (except the tes (more...)
Clips Controlling Other Clips - Movie clips can also control other movie clips. By using the _root or _parent keyword, you can send your commands up one level. Then, by using the name of the movie clip you want to address, yo (more...)
The Advantages of Flash - Flash is a very functional technology to enhance any web design and to add helpful components to any website. When used wisely and accurately, Flash gives you an opportunity to imp (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.