Flex4中StyleManager 修改样式

1. 问题:

Flex 4中用Flex 3代码:StyleManager.getStyleDeclaration('Button').setStyle('fontSize',24);

报错如下:

自 4.0 以来已弃用。 请使用 IStyleManager2.getStyleDeclaration on a style manager instance
获取存储指定 CSS 选择器规则的 CSSStyleDeclaration 对象。


2. 分析:

Flex4中不能再调用StyleManager类作为单例模式了。


3.解决:

StyleManager.getStyleManager(null).getStyleDeclaration('mx.controls.Button').setStyle('fontSize',24);


4. 实例代码:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
  xmlns:s="library://ns.adobe.com/flex/spark" 
  xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
  creationComplete="initApp(event)">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->

</fx:Declarations>

<fx:Style>

@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
mx|ToolTip {
fontSize: 50;
color: #ED1A3D;
backgroundColor: #000000;
}

.myStyle {
color: red;
}

</fx:Style>

<fx:Script>
<![CDATA[

public function initApp(e:Event):void {
import mx.managers.SystemManagerGlobals;
var manager:IStyleManager2 = StyleManager.getStyleManager(null);
var s:CSSStyleDeclaration = manager.getStyleDeclaration("mx.controls.ToolTip");
s.setStyle("fontSize", 50);
s.setStyle("color", 0xED1A3D);
s.setStyle("backgroundColor", 0x0);

//得到CSSStyleDeclaration类的样式并设定"Button"样式
manager.getStyleDeclaration("spark.components.Button"). setStyle("fontSize",24);
//设定一个新的样式名称
manager.getStyleDeclaration(".myStyle").setStyle("color",0xCC66CC);
}
]]>
</fx:Script>

<s:Button y="79" label="第一个按钮" horizontalCenter="0"  toolTip="button" />
<s:Label y="147"  id="myLabel"  text="This is a label"  styleName="myStyle" horizontalCenter="0"/>
</s:Application>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值