0

假设我在 mxml (sparkskin) 中有这个:

<s:SolidColor id="fillColor" 
                      color="0xff0000"
                      color.selectedOver="0xf74b47"
                      color.selectedUp="0xf74b47"/>

要在 AS3 中更改颜色属性,语法是:

fillcolor.color = 0x00ff00;

现在我想在 AS3 中更改 color.selectedOver。

有办法吗?

ie fillcolor['selectedOver'].color = 0x00ff00; ...
4

2 回答 2

0

你不能直接访问它,颜色只是 AS 中的一个整数属性。不确定是否有更好的方法,但您可以将颜色值绑定到变量并在运行时更改该变量:

// place this in your Script section 
[Bindable]
private var selectedOverColor:int = 0xf74b47;

// bind the color value to your variable
<s:SolidColor id="fillColor" 
                  color="0xff0000"
                  color.selectedOver="{selectedOverColor}"
                  color.selectedUp="0xf74b47"/>

// change this variable to the new color somewhere at runtime:
selectedOverColor = 0x000000;
于 2017-07-10T07:58:52.987 回答
0

谢谢,我同意。唯一的解决方案似乎覆盖 updateDisplayList 并使用类似的东西:

switch (currentState){
    case 'selectedOver':
       fillColor.color = 0xff0000;
       break;
    case 'selectedUp'
       fillColor.color = 0xffff00;
       break;

         ...
}
于 2017-07-11T09:02:31.533 回答