ColorPicker Component Tutorial

Published :
Author :
Adam Khoury
In this Flash ActionScript 3.0 tutorial we show how to dynamically program the ColorPicker component. Learn how to allow users to change colors on elements you want, and also learn how to access the value of their choice if using it in a form application. import fl.controls.ColorPicker; import fl.events.ColorPickerEvent; var rectWidth:uint = 450; var rectHeight:uint = 300; var bgColor:uint = 0xFFCC00; var borderColor:uint = 0x000000; var borderSize:uint = 2; var cornerRadius:uint = 12; var colorPicker:ColorPicker = new ColorPicker(); colorPicker.editable = true; colorPicker.move(20,10); addChild(colorPicker); drawRoundedRect(); function drawRoundedRect ():void { var roundedRect:Shape = new Shape; roundedRect.graphics.beginFill(bgColor); roundedRect.graphics.lineStyle(borderSize, borderColor); roundedRect.graphics.drawRoundRect(0,0, rectWidth, rectHeight, cornerRadius); roundedRect.graphics.endFill(); roundedRect.x = 60; roundedRect.y = 60; addChild(roundedRect); } colorPicker.addEventListener(ColorPickerEvent.CHANGE, colorChangeHandler); function colorChangeHandler(event:ColorPickerEvent):void { var newuint:uint = uint("0x"+event.target.hexValue); bgColor = newuint; removeChildAt(numChildren -1); drawRoundedRect(); }