1. Home
  2. Computing & Technology
  3. Animation

Flash “Coloring Book” with setRGB

By Adrien-Luc Sanders, About.com

8 of 10

Now that the value of hue is set, we need to use that value in our setRGB command to change the color of the block displaying the selected color:

on(release) {
_root.hue = 0x000000;
colorselected = new Color (_root.selected) ;
colorselected.setRGB(_root.hue) ;
}

colorselected = new Color (_root.selected) tells Flash that you want to define a new color function; setRGB won’t work without it. The formula is colorname = new Color (_root.instancename), where colorname can be anything that you want (as long as it isn’t an existing ActionsScript) and _root.instancename is the name of the instance on stage that you want to be affected by the fill color change. It’s basically saying “take this new color function, called “colorselected,” and apply it to instance “selected” on my stage when I use it in tandem with setRGB”.

colorselected.setRGB(_root.hue) then takes the new color, pairs it with the setRGB function, and defines the new fill color. The standard formula uses a hex value, such as colorselected.setRGB (0x000000), but for this case we’re just going to stick to the variable. We’ve told Flash to take the hex value assigned to the variable _root.hue and apply it to the fill of the instance named in colorselected. Now, when I click on the small black square, the larger square turns black – and I now have black assigned as my active color through the _root.hue variable.

Explore Animation
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Animation
  4. Flash Animation Tutorials
  5. Flash “Coloring Book” with setRGB

©2009 About.com, a part of The New York Times Company.

All rights reserved.