ColorPicker 组件允许用户从样本列表中选择颜色。
以下示例演示向面板容器添加矩形方块,点击这些方块将弹出调色板,监听调色板的选定颜色以更改方块的颜色。
从"库"面板中拖动相关组件到舞台(或直接通过 ActionScript 代码创建组件实例),并对实例命名。
在主时间轴中选择第一帧,打开"动作"面板,然后输入以下代码:
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.events.Event;
import flash.events.MouseEvent;
import shinater.swing.managers.PopUpManager;
var margin:int = 30;
for (var i:int = 0; i<5; i++) {
var mc:MovieClip = new MovieClip();
var g:Graphics = mc.graphics;
var color:uint = Math.random() * 0xFFFFFF;
g.lineStyle(5,color,0.5);
g.beginFill(color,0.8);
g.drawRect(0,0,50,50);
g.endFill();
mc.x = margin + (50 + margin) * i;
mc.y = 25;
mc.addEventListener(MouseEvent.CLICK,onClick);
my_panel.addChild(mc);
}
var ct:MovieClip;
function onClick(evt:MouseEvent){
ct = MovieClip(evt.currentTarget);
PopUpManager.show(my_clp,my_panel,my_panel.mouseX,my_panel.mouseY);
}
my_clp.addEventListener(Event.CHANGE, function(evt:Event){
PopUpManager.hide(my_clp);
var g:Graphics = ct.graphics;
g.clear();
var color:uint = my_clp.getSelectedColor();
g.lineStyle(5,color,0.5);
g.beginFill(color,0.8);
g.drawRect(0,0,50,50);
g.endFill();
});
my_clp.visible = false;
在线API文档地址:http://www.shinater.com/FlashSwing/Help/ColorPicker.html