0

我正在制作两个拾色器框。通过这两个颜色选择器框,我正在更改特定电影剪辑的颜色。我使用以下代码:

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;
}

这样,我只能访问最后一个颜色选择器框。请指导我

4

2 回答 2

0

因为你在说的时候修改了colorBox指针

 colorBox = new ColorPicker();

您可以创建一个数组,并将所有颜色选择器存储在那里,(或者作为一个不太好但更简单的解决方案,尝试定义 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)
 }
于 2013-04-12T14:49:50.700 回答
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;
}
于 2013-04-12T15:16:22.380 回答