Loading cascading style sheets(CSS) on the fly using the Flex StyleManager class


The following example shows how you can dynamically load a cascading style sheet SWF into your Flex application using the static StyleManager.loadStyleDeclarations() method.

Full code after the jump.

<?xml version=”1.0″ encoding=”utf-8″?>
<!– http://blog.flexexamples.com/2007/12/12/loading-cascading-style-sheets-on-the-fly-using-the-flex-stylemanager-class/ –>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml&#8221; 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>

~ by mjcprasad2000 on April 25, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: