Flex中如何利用StyleManager.loadStyleDeclarations()动态载入CSS SWF到Flex应用的例子
By Minidxer | January 2, 2009
接下来的例子演示了Flex中如何利用StyleManager.loadStyleDeclarations(),动态载入CSS SWF到Flex应用。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle">
- <mx:Script>
- <![CDATA[
- import mx.styles.StyleManager;
- private function loadStyles(styleURL:String):void {
- StyleManager.loadStyleDeclarations(styleURL);
- }
- ]]>
- </mx:Script>
- <mx:ApplicationControlBar dock="true">
- <mx:ComboBox id="comboBox"
- prompt="Please select a style"
- change="loadStyles(comboBox.selectedItem.data);">
- <mx:dataProvider>
- <mx:Array>
- <mx:Object label="red" data="styles/red.swf" />
- <mx:Object label="green" data="styles/green.swf" />
- <mx:Object label="blue" data="styles/blue.swf" />
- </mx:Array>
- </mx:dataProvider>
- </mx:ComboBox>
- </mx:ApplicationControlBar>
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
Other |
3 Comments » |
Tags: loadStyleDeclarations(), StyleManager
有错误啊!选择样式没有反映呢?
Error: Unable to load style(Error #2035: 找不到 URL。 URL: styles/green.swf): styles/green.swf.
swf路径有问题:
参考
http://blog.csdn.net/moreorless/article/details/6640054