我正在创建一个Flex主题,我正在定义默认的组件外观。所有按钮都应具有默认外观。可以使用styleName将特殊样式应用于按钮,styleName为按钮外观定义一组颜色。
我创建了一个Spark Button皮肤,如下所示:
<!-- ButtonSkin.mxml -->
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009" minWidth="21" minHeight="24" alpha.disabled="0.5">
<fx:Metadata>
<![CDATA[
[HostComponent("spark.components.Button")]
[Style(name="backgroundGradient", states="up, over, down", format="Array", inherit="yes")]
]]>
</fx:Metadata>
<fx:Script>
<![CDATA[
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
var backgroundGradient:Array = getStyle("backgroundGradient");
topGradientEntry.color = backgroundGradient[0];
bottomGradientEntry.color = backgroundGradient[1];
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
]]>
</fx:Script>
<s:states>
<s:State name="up" />
<s:State name="over" />
<s:State name="down" />
<s:State name="disabled" />
</s:states>
<!-- shapes using topGradientEntry.color and bottomGradientEntry.color -->
</s:Skin>
像这样设置主css文件:
/** default.css **/
s|Button {
skinClass: ClassReference('mytheme.skins.ButtonSkin');
fontWeight: bold;
}
skins|ButtonSkin {
backgroundGradient: 0x000000, 0xFFFFFF;
}
s|Button.btn-primary:up {
backgroundGradient: 0x000000, 0xFFFFFF;
}
s|Button.btn-primary:over {
backgroundGradient: 0x000000, 0xFFFFFF;
}
s|Button.btn-primary:down {
backgroundGradient: 0x000000, 0xFFFFFF;
}
s|Button.btn-inverted:up {
backgroundGradient: 0xFFFFFF, 0x000000;
}
s|Button.btn-inverted:over {
backgroundGradient: 0xFFFFFF, 0x000000;
}
s|Button.btn-inverted:down {
backgroundGradient: 0xFFFFFF, 0x000000;
}
应用程序会按如下方式设置按钮的样式:
<!-- Main.mxml -->
<s:Button label="Default" x="10" y="10" width="75" height="26"/>
<s:Button label="Button" x="110" y="10" width="75" height="26" styleName="btn-success"/>
<s:Button label="Primary" x="210" y="10" width="75" height="26" styleName="btn-primary"/>
但是我在所有情况下都得到错误“不支持'backgroundGradient'的CSS值。”
答案 0 :(得分:1)
我无法相信我在这个问题上花了多少时间。问题是CSS中的值应该使用带有#format格式的HEX,即#FFFFFF而不是0xFFFFFF。 Actionscript使用0x格式,MXML使用两者,而CSS使用HEX格式。