加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex4中StyleManager 修改样式

发布时间:2020-12-15 04:42:52 所属栏目:百科 来源:网络整理
导读:1. 问题: Flex 4中用Flex 3代码:StyleManager.getStyleDeclaration('Button').setStyle('fontSize',24); 报错如下: 自 4.0 以来已弃用。 请使用 IStyleManager2.getStyleDeclaration on a style manager instance 获取存储指定 CSS 选择器规则的 CSSStyle

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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读