12.13. Program: Color Selector Component
In this program, you create a color selector component similar to the one that is available from the Tools panel when you click on either the stroke or fill color. To do this, follow these steps:
Create a new movie clip symbol named
ColorSelector
.Open the Linkage properties for
ColorSelector
using the Library panel’s pop-up Options menu. Export the symbol for ActionScript and give it a linkage identifier of ColorSelectorSymbol.On the first frame of the default layer of
ColorSelector
, add the following code:#initclip function ColorSelectorClass ( ) { // Define color transform object properties.
resetTransform
resets a movie // clip's colors back to the symbol's original values.selectTransform
sets the // movie clip's colors to white. this.resetTransform = {ra: 100, rb: 0, ga: 100, gb: 0, ba: 100, bb: 0, aa: 100, ab: 0}; this.selectTransform = {ra: 100, rb: 255, ga: 100, gb: 255, ba: 100, bb: 255, aa: 100, ab: 0}; // Thenum
property is used to count the number of color swatches. this.num = 0; // TheselectedColor
property is the RGB value // of the color selected by the user. this.selectedColor = 0; // Call thestartListeners( )
method to watch theselectedColor
property. This // custom handler is implemented in Recipe 12.11. this.startListeners("selectedColor"); // Create a movie clip to hold all the color swatches and initially set it to // be invisible. Set the y position of theswatches_mc
movie clip to 15 so that // it appears below ...
Get Actionscript Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.