我正在制作两个颜色选择器盒。通过这两个颜色选择器框,我正在改变颜色特定的影片剪辑。我用以下代码:
for (var i:int = 0; i < 1; i++)
{
color_picker(i)
}
var colorBox:ColorPicker;
var mc:MovieClip= new MovieClip()
addChild(mc)
function color_picker(p)
{
colorBox = new ColorPicker();
mc.addChild(colorBox);
colorBox.x = 0
colorBox.y = p * 40;
p++;
colorBox.addEventListener(ColorPickerEvent.CHANGE, changeColor1)
}
var colorTransform1:ColorTransform = new ColorTransform();
function changeColor1(Event:ColorPickerEvent)
{
var color = "0x" +Event.currentTarget.selectedColor.toString(16);
colorTransform.color = color;
cards.getChildAt(0).transform.colorTransform = colorTransform;
}
通过这个我只访问最后一个颜色选择器框。 请指导我
答案 0 :(得分:0)
因为你在说
时修改了colorBox指针 colorBox = new ColorPicker();
你可以创建一个数组,并将所有colorPickers存储在那里,(或者作为一个不太好但更简单的解决方案,尝试定义colorBox1和colorBox2。)
function color_picker(p) {
array.push(new ColorPicker())
colorBox = array[array.length-1]
mc.addChild(colorBox);
colorBox.x = 0
colorBox.y = p * 40;
p++;
colorBox.addEventListener(ColorPickerEvent.CHANGE, changeColor1)
}
答案 1 :(得分:0)
var mc:MovieClip= new MovieClip()
addChild(mc)
for (var i:int = 0; i < 1; i++)
{
color_picker(i)
}
function color_picker(p)
{
var colorBox = new ColorPicker();
mc.addChild(colorBox);
colorBox.x = 0
colorBox.y = p * 40;
//p++; //NO NEED TO INCREMENT THIS VALUE, IT'S GETTING FROM THE LOOP
colorBox.addEventListener(ColorPickerEvent.CHANGE, changeColor1)
}
var colorTransform1:ColorTransform = new ColorTransform();
function changeColor1(Event:ColorPickerEvent)
{
var color = "0x" +Event.currentTarget.selectedColor.toString(16);
colorTransform.color = color;
cards.getChildAt(0).transform.colorTransform = colorTransform;
}