AS3更改所有按钮颜色



我正在尝试使用此代码替换所有称为'mybuttons'的按钮的颜色:

        colorTransform.color = 0xaf4b44;
        myButtons.transform.colorTransform = colorTransform;

,但只有最近创建的按钮才会改变颜色,而不是全部。他们都被称为mybuttons。还有另一种方法吗?

如果所有按钮都具有相同的父,则可以使用以下代码。我建议您为每个按钮使用其他名称。

var colorTransform:ColorTransform=new ColorTransform;
colorTransform.color = 0xaf4b44;
var mc:MovieClip=new MovieClip;
mc=root["myButtons"].parent;
for(var i:int=0; i<mc.numChildren; i++){
    if(mc.getChildAt(i).name=="myButtons"){
        mc.getChildAt(i).transform.colorTransform = colorTransform;
    }
}

最新更新