|
The Color object in flash The color object in flash allows us to set RGB color value to movie clip symbols. They also help us retrieve the value once set First and foremost, we will have to create a color object before calling its methods.
public Color(target:Object) The above code creates a color object for the movie clip specified by the 'target_mc' parameter. We can then use methods of that color object to change color of entire target movie clip. Color class methods - - getRGB()
- getTransform()
- setRGB()
- setTransform()
setRGB() sets an hexadecimal color value to the entire movie clip. setTransform() helps us set detailed color values to the movie clip. Here you get to decide the amount of red, green, blue and alpha value you would like to add to your movie clip. As setTransform goes into details, it is a little complicated to use. Let me list out the variables used in set Transform – - 'ra' is the percentage for the red component (-100 to 100).
- 'rb' is the offset for the red component (-255 to 255).
- 'ga' is the percentage for the green component (-100 to 100).
- 'gb' is the offset for the green component (-255 to 255).
- 'ba' is the percentage for the blue component (-100 to 100).
- 'bb' is the offset for the blue component (-255 to 255).
- 'aa' is the percentage for alpha (-100 to 100).
- 'ab' is the offset for alpha (-255 to 255).
Below is a simple example on how we can set RGB to movie clip Please follow steps below to create flash color pallete as shown above.
- Draw a vector rectangular diagram which fits the entire screen on your canvas
- Convert the same to a movie clip symbol and give an instance name as 'color1_mc'
- Add another layer above this
- Drag the above movie clip symbol from your library to your canvas and reduce their sizes to 25 x 25 px. Place the same in the bottom.
- Give any tint color you like
- Similarly, repeat the above 2 steps and create a pallete of colors as shown in the above flash 'color pallete' example
- Create another layer and name it 'actions'
- Now lets begin with the actionscript coding
- Select 'Frame1' of actionscript layer, and in your actions window paste below script
var my_color:Color = new Color(color_mc); |
The above code is to create a color object. As you can recollect, this is the first step which needs to be done.
- Select each color option small square movie clip and in their rescetive action window, Paste the below code and change hexadecimal color value to the ones you want.
eg - 0 x the hexadecimal color code
on(release) { _root.my_color.setRGB(0x3a505f); } |
- Your color pallete is ready. Press ctrl+Enter to view the same. Click on the color options and you can see your background color change.
Click here to download the source file.
Tags: Color Object in Flash, Color using actionscript, RGB() actionscripting
|