Flex4 - 使用CSSStyleDeclaration在运行时动态设置,改变css样式
1,获取样式表里已存在的样式并设置(可修改或添加)
2,设置新样式
var selector1:CSSStyleDeclaration = styleManager.getStyleDeclaration(".myBtn"); selector1.setStyle("fontSize","14"); var selector2:CSSStyleDeclaration = styleManager.getStyleDeclaration("spark.components.Button"); selector2.setStyle("fontSize","14");
2,设置新样式
var selector1:CSSStyleDeclaration = new CSSStyleDeclaration(); selector1.setStyle("color","0xff0000"); styleManager.setStyleDeclaration("spark.components.Button",selector1,false); var selector2:CSSStyleDeclaration = new CSSStyleDeclaration(); selector2.setStyle("fontSize","25"); styleManager.setStyleDeclaration(".btn1",selector2,true); //由于设置样式消耗资源很大,所以只在最后一个样式里将最后参数设置为true,表示立刻更新样式