在Flex3.0中改变样式方法:
在Flex4.0中报出警告:
"3608: ewZ文_'getStyleDeclaration' has been deprecated since 4.0. Please use 'IStyleManager2.getStyleDeclaration on a style manager instance'."
正确的方法为:
其中"global"是你的CSS选择器的名称,可以是常用的类型选择器如 Button { color: #FF0000 },也可以是以"."开头的类选择器,如".redButton { color: #FF0000 }"。
CSSStyleDeclaration 类表示一组 CSS 样式规则。
可使用 FlexGlobals.topLevelApplication.styleManager.getStyle()、setStyle() 和 clearStyle() 方法获取、设置和清除 CSSStyleDeclaration 上的样式属性。
还可以使用 FlexGlobals.topLevelApplication.styleManager.setStyleDeclaration() 方法在运行时创建和安装 CSSStyleDeclaration。
完整示例:
还有,使用类型选择器时要记得把namespace写完整,如spark.components.Button或者mx.controls.Button,否则编译器不知道你到底要调用哪个Button,容易报出空指针。
StyleManager.getStyleDeclaration('Button').setStyle('fontSize',24);
在Flex4.0中报出警告:
"3608: ewZ文_'getStyleDeclaration' has been deprecated since 4.0. Please use 'IStyleManager2.getStyleDeclaration on a style manager instance'."
正确的方法为:
var cssDeclaration:CSSStyleDeclaration = FlexGlobals.topLevelApplication.styleManager.getStyleDeclaration(‘global’);
cssDeclaration.setStyle(‘themeColor’, ‘0x’+gradient_to);
其中"global"是你的CSS选择器的名称,可以是常用的类型选择器如 Button { color: #FF0000 },也可以是以"."开头的类选择器,如".redButton { color: #FF0000 }"。
CSSStyleDeclaration 类表示一组 CSS 样式规则。
可使用 FlexGlobals.topLevelApplication.styleManager.getStyle()、setStyle() 和 clearStyle() 方法获取、设置和清除 CSSStyleDeclaration 上的样式属性。
还可以使用 FlexGlobals.topLevelApplication.styleManager.setStyleDeclaration() 方法在运行时创建和安装 CSSStyleDeclaration。
完整示例:
var newStyleDeclaration:CSSStyleDeclaration = new CSSStyleDeclaration(".bigMargins");
newStyleDeclaration.defaultFactory = function():void
{
leftMargin = 50;
rightMargin = 50;
}
FlexGlobals.topLevelApplication.styleManager.setStyleDeclaration(".bigMargins", newStyleDeclaration, true);
还有,使用类型选择器时要记得把namespace写完整,如spark.components.Button或者mx.controls.Button,否则编译器不知道你到底要调用哪个Button,容易报出空指针。