Of course to begin don’t forget to drop this component in your library. A simple demonstration of assigning a color to an object being added to the stage.
Here is the Document Class file ColorPickerComponent.as:
package
{
import flash.display.Sprite;
import flash.display.Shape;
import fl.controls.ColorPicker;
import fl.events.ColorPickerEvent;
import flash.geom.ColorTransform;
public class ColorPickerComponent extends Sprite
{
private var bg:Shape; // for the background
private var tf:ColorTransform;
private var holder:Sprite;
public function ColorPickerComponent()
{
colorBox("000000");
var myColorPicker:ColorPicker = new ColorPicker();
myColorPicker.addEventListener(ColorPickerEvent.CHANGE, changeHandler);
myColorPicker.move(10, 10);
addChild(myColorPicker);
}
private function changeHandler(e:ColorPickerEvent):void {
colorBox(e.target.hexValue);
}
private function colorBox(color:String)
{
if (numChildren != 0) // check to see if there are any shapes
{
removeChildAt(0); // removes the shape
}
var bg:Shape = new Shape();
bg.graphics.beginFill(0x336699);
bg.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
var tf:ColorTransform = bg.transform.colorTransform;
var newcolor = "0x" + color;
tf.color = newcolor;
bg.transform.colorTransform = tf;
addChildAt(bg,0);
}
}
}
in flash, i’m getting:
1046: Type was not found or was not a compile-time constant: ColorPickerEvent.
any ideas?
You forgot the import