Flex中如何利用StyleManager.loadStyleDeclarations()动态载入CSS SWF到Flex应用的例子

By Minidxer | January 2, 2009

接下来的例子演示了Flex中如何利用StyleManager.loadStyleDeclarations(),动态载入CSS SWF到Flex应用。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="middle">
  5.  
  6.     <mx:Script>
  7.         <![CDATA[
  8.             import mx.styles.StyleManager;
  9.  
  10.             private function loadStyles(styleURL:String):void {
  11.                 StyleManager.loadStyleDeclarations(styleURL);
  12.             }
  13.         ]]>
  14.     </mx:Script>
  15.  
  16.     <mx:ApplicationControlBar dock="true">
  17.         <mx:ComboBox id="comboBox"
  18.                 prompt="Please select a style"
  19.                 change="loadStyles(comboBox.selectedItem.data);">
  20.             <mx:dataProvider>
  21.                 <mx:Array>
  22.                     <mx:Object label="red" data="styles/red.swf" />
  23.                     <mx:Object label="green" data="styles/green.swf" />
  24.                     <mx:Object label="blue" data="styles/blue.swf" />
  25.                 </mx:Array>
  26.             </mx:dataProvider>
  27.         </mx:ComboBox>
  28.     </mx:ApplicationControlBar>
  29.  
  30. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Other | 3 Comments » | Tags: ,

你可能还对下列文章感兴趣:

3 comments | Add One

  1. alex - 06/22/2010 at 1:20 pm

    有错误啊!选择样式没有反映呢?

  2. leo - 07/28/2011 at 9:43 am

    Error: Unable to load style(Error #2035: 找不到 URL。 URL: styles/green.swf): styles/green.swf.

  3. leo - 07/28/2011 at 10:30 am

Leave a Comment

Name(*):

E-Mail(*) :

Website :

Comments :

Search Posts