<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gaurav&#039;s Blog &#187; Gaurav</title>
	<atom:link href="http://gauravj.com/blog/author/Gaurav/feed/" rel="self" type="application/rss+xml" />
	<link>http://gauravj.com/blog</link>
	<description>Tips and Tools of Flex</description>
	<lastBuildDate>Thu, 18 Mar 2010 18:34:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Styles and popups with Flex 4</title>
		<link>http://gauravj.com/blog/2010/03/styles-and-popups-with-flex-4/</link>
		<comments>http://gauravj.com/blog/2010/03/styles-and-popups-with-flex-4/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 18:25:06 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[Flex Framework]]></category>
		<category><![CDATA[Alert]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[PopUpManager]]></category>
		<category><![CDATA[Styles]]></category>
		<category><![CDATA[TitleWindow]]></category>
		<category><![CDATA[ToolTipManager]]></category>

		<guid isPermaLink="false">http://gauravj.com/blog/?p=703</guid>
		<description><![CDATA[<p>If you use modules/sub apps and pop ups(Alert, ToolTip, TitleWindow, etc.) then you probably would be interested in some of the api changes that were introduced by the “Per-Module Style Management” feature in Flex 4. As I mentioned in my previous posts that StyleManager is no longer a singleton class and all modules and sub apps <span style="color:#777"> . . . &#8594; Read More: <a href="http://gauravj.com/blog/2010/03/styles-and-popups-with-flex-4/">Styles and popups with Flex 4</a></span>]]></description>
			<content:encoded><![CDATA[<p>If you use modules/sub apps and pop ups(Alert, ToolTip, TitleWindow, etc.) then you probably would be interested in some of the api changes that were introduced by the “Per-Module Style Management” feature in Flex 4. As I mentioned in my previous posts that StyleManager is no longer a singleton class and all modules and sub apps have their own instance of the Style Manager. So when you define a style in a module or sub app, the style definition is managed by the style manager instance of the module/sub app. This works well for most components but pop ups are a special case (all pop ups depend on the PopUpManager) </p>
<p>PopUpManager is a singleton and hence it lives in the top level application domain. When a component is displayed using the PopUpManager it will try to get its styles via the StyleManager in the top level application domain and so the styles that are defined in your module/sub app will be ignored. In order to provide a solution for this situation some apis were modified to accept a new optional parameter. Via the optional parameter the module factory can be specified (which is then internally used to locate the correct style manager). Some apis that were modified are:</p>
<ul>
<li>mx.controls.Alert &#8211; show() method was modified to take an optional moduleFactory parameter</li>
<li>mx.manager.PopUpManager- createPopUp() and addPopUp() methods were modified to take an optional moduleFactory parameter</li>
</ul>
<p>So if you are defining styles in your modules/sub apps, you should then pass the moduleFactory parameter to these methods. Lets look at some examples:</p>
<p>Following the code for a main app that loads one module(which shows Alert and TitleWindow) and one sub application (which shows ToolTip). </p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Application</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span style="color: #000000;">			   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> width=<span style="color: #ff0000;">&quot;600&quot;</span> height=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Style</span><span style="color: #7400FF;">&gt;</span></span>
		@namespace s &quot;library://ns.adobe.com/flex/spark&quot;;
		@namespace mx &quot;library://ns.adobe.com/flex/mx&quot;;
&nbsp;
		s|TitleWindow
		{
			chromeColor: #FF0000;
		}
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Style</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">			import mx.events.FlexEvent;</span>
<span style="color: #000000;">			import mx.managers.PopUpManager;</span>
&nbsp;
<span style="color: #000000;">			import spark.components.TitleWindow;</span>
&nbsp;
<span style="color: #000000;">			private var placeHolder: PopUpManager;</span>
<span style="color: #000000;">			private var placeHolder2: TitleWindow;</span>
&nbsp;
<span style="color: #000000;">			protected function popup_load_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				if<span style="color: #66cc66;">&#40;</span>mod_loader_pop.url == null<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">					mod_loader_pop.url = <span style="color: #ff0000;">&quot;PopUpModule.swf&quot;</span>;</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#125;</span> else <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">					mod_loader_pop.loadModule<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			protected function popup_unload_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				mod_loader_pop.unloadModule<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			protected function toolTip_load_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				swfLoader.load<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ToolTipSubApp.swf&quot;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			protected function toolTip_unload_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				swfLoader.unloadAndStop<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VerticalLayout</span> paddingTop=<span style="color: #ff0000;">&quot;5&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;popup_load&quot;</span> label=<span style="color: #ff0000;">&quot;Load PopUp Module&quot;</span> click=<span style="color: #ff0000;">&quot;popup_load_clickHandler(event)&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;popup_unload&quot;</span> label=<span style="color: #ff0000;">&quot;Unload PopUp Module&quot;</span> click=<span style="color: #ff0000;">&quot;popup_unload_clickHandler(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;toolTip_load&quot;</span> label=<span style="color: #ff0000;">&quot;Load ToolTip App&quot;</span> click=<span style="color: #ff0000;">&quot;toolTip_load_clickHandler(event)&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;toolTip_unload&quot;</span> label=<span style="color: #ff0000;">&quot;Unload ToolTip App&quot;</span> click=<span style="color: #ff0000;">&quot;toolTip_unload_clickHandler(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ModuleLoader</span> id=<span style="color: #ff0000;">&quot;mod_loader_pop&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SWFLoader</span> id=<span style="color: #ff0000;">&quot;swfLoader&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

</blockquote>
<p>If you notice, the above app sets the chromeColor for the TitleWindow to #FF0000. Also it does not use any Alert.</p>
<p>Let&#8217;s look at the code for the module (PopUpModule.mxml):</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Module</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">		   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #000000;">		   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> <span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Style</span><span style="color: #7400FF;">&gt;</span></span>
		@namespace s &quot;library://ns.adobe.com/flex/spark&quot;;
		@namespace mx &quot;library://ns.adobe.com/flex/mx&quot;;
&nbsp;
		s|TitleWindow
		{
			fontSize: 32;
		}
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Style</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">			import mx.events.CloseEvent;</span>
<span style="color: #000000;">			import mx.managers.PopUpManager;</span>
<span style="color: #000000;">			import spark.components.TitleWindow;</span>
<span style="color: #000000;">			import mx.controls.Alert;</span>
&nbsp;
<span style="color: #000000;">			public var titleWindow: TitleWindow;</span>
&nbsp;
<span style="color: #000000;">			protected function btn1_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				Alert.show<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;clicked&quot;</span>,<span style="color: #ff0000;">&quot;module&quot;</span>,<span style="color: #cc66cc;">4</span>,null,null,null,<span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			protected function btn2_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				Alert.show<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;clicked&quot;</span>,<span style="color: #ff0000;">&quot;module&quot;</span>,<span style="color: #cc66cc;">4</span>,null,null,null,<span style="color: #cc66cc;">4</span> , this.moduleFactory<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			protected function btn1_1_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				titleWindow = PopUpManager.createPopUp<span style="color: #66cc66;">&#40;</span>DisplayObject<span style="color: #66cc66;">&#40;</span>systemManager<span style="color: #66cc66;">&#41;</span>,TitleWindow, true, null<span style="color: #66cc66;">&#41;</span> as TitleWindow;</span>
<span style="color: #000000;">				titleWindow.title =<span style="color: #ff0000;">&quot;Title Window&quot;</span>;</span>
<span style="color: #000000;">				titleWindow.width = <span style="color: #cc66cc;">136</span>;</span>
<span style="color: #000000;">				titleWindow.addEventListener<span style="color: #66cc66;">&#40;</span>CloseEvent.CLOSE, closeMe, false, <span style="color: #cc66cc;">0</span>, true<span style="color: #66cc66;">&#41;</span>; </span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			protected function btn2_1_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				titleWindow = PopUpManager.createPopUp<span style="color: #66cc66;">&#40;</span>DisplayObject<span style="color: #66cc66;">&#40;</span>systemManager<span style="color: #66cc66;">&#41;</span>,TitleWindow, true, null, moduleFactory<span style="color: #66cc66;">&#41;</span> as TitleWindow;</span>
<span style="color: #000000;">				titleWindow.title =<span style="color: #ff0000;">&quot;Module Title Window&quot;</span>;</span>
<span style="color: #000000;">				titleWindow.width = <span style="color: #cc66cc;">426</span>;</span>
<span style="color: #000000;">				titleWindow.addEventListener<span style="color: #66cc66;">&#40;</span>CloseEvent.CLOSE, closeMe, false, <span style="color: #cc66cc;">0</span>, true<span style="color: #66cc66;">&#41;</span>; </span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			private function closeMe<span style="color: #66cc66;">&#40;</span>e:CloseEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				PopUpManager.removePopUp<span style="color: #66cc66;">&#40;</span>titleWindow<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">				titleWindow.removeEventListener<span style="color: #66cc66;">&#40;</span>CloseEvent.CLOSE, closeMe<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Panel</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> title=<span style="color: #ff0000;">&quot;PopUp Module &quot;</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VerticalLayout</span> paddingTop=<span style="color: #ff0000;">&quot;5&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> label=<span style="color: #ff0000;">&quot;Show alert&quot;</span> id=<span style="color: #ff0000;">&quot;btn1&quot;</span> click=<span style="color: #ff0000;">&quot;btn1_clickHandler(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> label=<span style="color: #ff0000;">&quot;Show alert (with moduleFactory)&quot;</span> id=<span style="color: #ff0000;">&quot;btn2&quot;</span> click=<span style="color: #ff0000;">&quot;btn2_clickHandler(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> label=<span style="color: #ff0000;">&quot;show title window&quot;</span> id=<span style="color: #ff0000;">&quot;btn1_1&quot;</span> click=<span style="color: #ff0000;">&quot;btn1_1_clickHandler(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> label=<span style="color: #ff0000;">&quot;show title window (with moduleFactory)&quot;</span> id=<span style="color: #ff0000;">&quot;btn2_1&quot;</span> click=<span style="color: #ff0000;">&quot;btn2_1_clickHandler(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Panel</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Module</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

</blockquote>
<p>The module defines the fontSize for the TitleWindow. Also it has two calls to Alert.show() (with and without the moduleFactory parameter). Similarly two calls to PopUpManager.createPopUp() (with and without the moduleFactory parameter). When you run the example code, you will notice the only the Alert and TitleWindow displayed with the moduleFactory parameter are able to pick the correct styles. </p>
<p>Before looking at the running swf, lets also look at the code for the sub application (ToolTipSubApp.mxml):</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Application</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> height=<span style="color: #ff0000;">&quot;200&quot;</span> width=<span style="color: #ff0000;">&quot;200&quot;</span> </span>
<span style="color: #000000;">			   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">			import flash.events.MouseEvent;</span>
&nbsp;
<span style="color: #000000;">			import mx.core.IToolTip;</span>
<span style="color: #000000;">			import mx.managers.ToolTipManager;</span>
&nbsp;
<span style="color: #000000;">			public var mytoolTip:IToolTip;</span>
&nbsp;
<span style="color: #000000;">			protected function panel1_mouseOverHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				if<span style="color: #66cc66;">&#40;</span>useContext.selected<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">					mytoolTip = ToolTipManager.createToolTip<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;This is a custom tooltip in a sub App&quot;</span>, <span style="color: #cc66cc;">100</span>, <span style="color: #cc66cc;">100</span>, null,this<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#125;</span> else <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">					mytoolTip = ToolTipManager.createToolTip<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;This is a custom tooltip in a sub App&quot;</span>, <span style="color: #cc66cc;">100</span>, <span style="color: #cc66cc;">100</span>, null<span style="color: #66cc66;">&#41;</span>;					</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			protected function panel1_mouseOutHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				ToolTipManager.destroyToolTip<span style="color: #66cc66;">&#40;</span>mytoolTip<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Style</span><span style="color: #7400FF;">&gt;</span></span>
		@namespace ns &quot;library://ns.adobe.com/flex/mx&quot;;
		@namespace s &quot;library://ns.adobe.com/flex/spark&quot;;
&nbsp;
		ns|ToolTip
		{
			color: blue;
			fontSize: 22;
		}
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Style</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VerticalLayout</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Panel</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;90%&quot;</span> mouseOver=<span style="color: #ff0000;">&quot;panel1_mouseOverHandler(event)&quot;</span> mouseOut=<span style="color: #ff0000;">&quot;panel1_mouseOutHandler(event)&quot;</span> title=<span style="color: #ff0000;">&quot;Sub App&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Panel</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:CheckBox</span> label=<span style="color: #ff0000;">&quot;pass context&quot;</span> id=<span style="color: #ff0000;">&quot;useContext&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

</blockquote>
<p>The sub app contains a Panel and a CheckBox, it also contains a style declaration for the ToolTip. When you move the mouse over the panel it displays a tooltip. By default it does not passes the context to the createToolTip method, but when the checkbox is selected it passes the content parameter. In the previous releases the context parameter was not used, but starting from Flex 4 it is being used to locate the current moduleFactory. Only when you pass the context (by selecting the checkbox) the styles for ToolTip defined in the sub app are picked. </p>
<p>Let&#8217;s look at the running swf now:<br />
<center><br />
<iframe src ="http://gauravj.com/blog/examples/Styles/PerModuleStyles_3/StylesAndPopUps.html" width="600" height="500"></p>
<p>Your browser does not support iframes.</p>
<p></iframe><br />
</center></p>
<p>If you load the PopUp Module and click on the &#8220;Show alert&#8221; button, you would notice that the Alert doesn&#8217;t show up with the proper window or title bar. This reason for this broken appearance of Alert is that when the module factory is *not* passed, Alert will try to get its style from the top level style manager. But the main app does not use Alert, so the styles for Alert are not available in the main app. The solution is to pass the moduleFactory to the Alert.show() method. When you click on the &#8220;Show Alert (with moduleFactory)&#8221; button, you would see an Alert with correct Styles.</p>
<p>Also when you click on the &#8220;Show title window&#8221; button, you would notice that the title window shows up with chromeColor red but the fontSize style defined in the module is ignored. This reason for this is same (i.e. when the module factory is *not* passed, TitleWindow will try to get its style from the top level style manager. But the main app only sets chromeColor to red, and the modified fontSize style is not available in the main app) . The solution is to pass the moduleFactory to the PopUpManager.createPopUp() method. And when you click on the &#8220;Show title window (with moduleFactory)&#8221; button, you would see an TitleWindow with correct fontSize and chromeColor.</p>
<p>You would also notice similar behavioral difference when you load the Tool Tip app and play with the tool tip. The ToolTip styles defined in the sub app will only be picked when you pass the context (by selecting the checkbox) to the ToolTipManager.createToolTip() method. Passing the context sets the correct moduleFactory (which is then used to get to the correct style manager). </p>
<p>So, I hope you find this information useful and continue to create awesome looking and mind blowing apps.  </p>
]]></content:encoded>
			<wfw:commentRss>http://gauravj.com/blog/2010/03/styles-and-popups-with-flex-4/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>StyleManager in Flex 4</title>
		<link>http://gauravj.com/blog/2010/02/stylemanager-in-flex-4/</link>
		<comments>http://gauravj.com/blog/2010/02/stylemanager-in-flex-4/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 22:31:51 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[Flex Framework]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Styles]]></category>

		<guid isPermaLink="false">http://gauravj.com/blog/?p=653</guid>
		<description><![CDATA[<p>In my previous post stylish modules and sub applications, I mentioned that StyleManager is not going to be a singleton class in Flex 4. There are some more StyleManager related api changes that you should be aware of.</p>
<p>StyleManager now implements IStyleManager2. If you recompile your Flex 3 app using Flex 4 SDK, you will get deprecation <span style="color:#777"> . . . &#8594; Read More: <a href="http://gauravj.com/blog/2010/02/stylemanager-in-flex-4/">StyleManager in Flex 4</a></span>]]></description>
			<content:encoded><![CDATA[<p>In my previous post <a href="http://gauravj.com/blog/2010/02/stylish-modules-and-sub-applications/">stylish modules and sub applications</a>, I mentioned that StyleManager is not going to be a singleton class in Flex 4. There are some more StyleManager related api changes that you should be aware of.</p>
<p>StyleManager now implements IStyleManager2. If you recompile your Flex 3 app using Flex 4 SDK, you will get deprecation warnings because all static methods of StyleManager class except for getStyleManager() have been deprecated. In order to get rid of the deprecation warnings, you will need to use the StyleManager instance. You can either get the StyleManager instance using the getStyleManager() method or change StyleManager to styleManager (notice the lower case &#8216;s&#8217;). mx.core.UIComponent now has a new public property called styleManager which is a reference to your current StyleManager. </p>
<p>Also StyleManager now has a new method called getMergedStyleDeclaration() which can be used to get the merged style declarations (both declared in the current style manager and those inherited from the parent style managers). One thing to be aware of with this method is that CSSStyleDeclaration obtained via this method can not be used to modify style values. In order to modify style values, you will have to obtain CSSStyleDeclaration using the getStyleDeclaration() method. </p>
<p>Lets look at an example:<br />
Here is the code for an application that defines Style for a spark List (specifically it defines the borderColor and fontSize). </p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Application</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">			   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #000000;">			   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> minWidth=<span style="color: #ff0000;">&quot;1024&quot;</span> minHeight=<span style="color: #ff0000;">&quot;768&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;application1_creationCompleteHandler(event)&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Style</span><span style="color: #7400FF;">&gt;</span></span>
		@namespace s &quot;library://ns.adobe.com/flex/spark&quot;;
		@namespace mx &quot;library://ns.adobe.com/flex/mx&quot;;
&nbsp;
		s|List
		{
			borderColor: #0000FF;
			fontSize: 16;
		}
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Style</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">			import mx.collections.ArrayList;</span>
<span style="color: #000000;">			import mx.events.FlexEvent;</span>
<span style="color: #000000;">			import spark.components.TextInput;</span>
<span style="color: #000000;">                        // The following two lines <span style="color: #66cc66;">&#40;</span>import and var declaration for PopUpManager<span style="color: #66cc66;">&#41;</span> are to make sure that PopUpManager gets sucked into the app. Since PopUpManager</span>
<span style="color: #000000;">                        //  is a singleton, its definition should be available in the main app</span>
<span style="color: #000000;">                        // Otherwise module will throw an RTE when ColorPicker is used.</span>
<span style="color: #000000;">			import mx.managers.PopUpManager;			</span>
<span style="color: #000000;">			private var ph:PopUpManager;</span>
&nbsp;
<span style="color: #000000;">			private var arr:Array =</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Apple'</span>, data:<span style="color: #cc66cc;">10.00</span><span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Banana'</span>, data:<span style="color: #cc66cc;">15.00</span> <span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Melon'</span>, data:<span style="color: #cc66cc;">3.50</span> <span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Kiwi'</span>, data:<span style="color: #cc66cc;">7.65</span><span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Strawberry'</span>,data:<span style="color: #cc66cc;">12.35</span> <span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Other'</span>, data:<span style="color: #cc66cc;">00.00</span><span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#93;</span>;</span>
&nbsp;
<span style="color: #000000;">			private var listArr :ArrayList = new ArrayList<span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#41;</span>;</span>
&nbsp;
<span style="color: #000000;">			protected function application1_creationCompleteHandler<span style="color: #66cc66;">&#40;</span>event:FlexEvent<span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				appList.dataProvider = listArr;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			public function iniit<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				mod_loader.url = <span style="color: #ff0000;">&quot;ModifyCSSDeclarationModule.swf&quot;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			public function unload<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				mod_loader.unloadModule<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">				mod_loader.url = <span style="color: #ff0000;">&quot;&quot;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VerticalLayout</span> paddingTop=<span style="color: #ff0000;">&quot;5&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;5&quot;</span> paddingRight=<span style="color: #ff0000;">&quot;5&quot;</span> paddingBottom=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HGroup</span> id=<span style="color: #ff0000;">&quot;hgroupContainer&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:List</span> id=<span style="color: #ff0000;">&quot;appList&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ModuleLoader</span> id=<span style="color: #ff0000;">&quot;mod_loader&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> label=<span style="color: #ff0000;">&quot;Load Module&quot;</span> click=<span style="color: #ff0000;">&quot;iniit()&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> label=<span style="color: #ff0000;">&quot;UnLoad Module&quot;</span> click=<span style="color: #ff0000;">&quot;unload()&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

</blockquote>
<p>Below is the code for the module (ModifyCSSDeclarationModule.mxml) loaded by the app:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Module</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">		   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #000000;">		   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;module1_creationCompleteHandler(event)&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Style</span><span style="color: #7400FF;">&gt;</span></span>
		@namespace s &quot;library://ns.adobe.com/flex/spark&quot;;
		@namespace mx &quot;library://ns.adobe.com/flex/mx&quot;;
&nbsp;
		s|List
		{
			fontStyle: italic;
			color: #FF0000;
		}
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Style</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">			import mx.collections.ArrayList;</span>
<span style="color: #000000;">			import mx.events.FlexEvent;</span>
&nbsp;
<span style="color: #000000;">			private var arr:Array =</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Apple'</span>, data:<span style="color: #cc66cc;">10.00</span><span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Banana'</span>, data:<span style="color: #cc66cc;">15.00</span> <span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Melon'</span>, data:<span style="color: #cc66cc;">3.50</span> <span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Kiwi'</span>, data:<span style="color: #cc66cc;">7.65</span><span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Strawberry'</span>,data:<span style="color: #cc66cc;">12.35</span> <span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Other'</span>, data:<span style="color: #cc66cc;">00.00</span><span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#93;</span>;</span>
&nbsp;
<span style="color: #000000;">			private var listArr :ArrayList = new ArrayList<span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			private var myStyleManager: IStyleManager2;</span>
&nbsp;
<span style="color: #000000;">			protected function module1_creationCompleteHandler<span style="color: #66cc66;">&#40;</span>event:FlexEvent<span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				moduleList.dataProvider = listArr;</span>
<span style="color: #000000;">				myStyleManager = StyleManager.getStyleManager<span style="color: #66cc66;">&#40;</span>this.moduleFactory<span style="color: #66cc66;">&#41;</span>;	</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			public function modifyStyleValue<span style="color: #66cc66;">&#40;</span>  <span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				var cssDecl:CSSStyleDeclaration = myStyleManager.getStyleDeclaration<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;spark.components.List&quot;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">				cssDecl.setStyle<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;color&quot;</span>, colorPicker.value<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">				cssDecl.setStyle<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;borderColor&quot;</span>, colorPicker.value<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			public function modifyMergedStyleValue<span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				var cssDecl:CSSStyleDeclaration = myStyleManager.getMergedStyleDeclaration<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;spark.components.List&quot;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">				cssDecl.setStyle<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;borderColor&quot;</span>, colorPicker.value<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">				cssDecl.setStyle<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;color&quot;</span>, colorPicker.value<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:List</span> id=<span style="color: #ff0000;">&quot;moduleList&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;Choose Color&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>	
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ColorPicker</span> id=<span style="color: #ff0000;">&quot;colorPicker&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;localButton&quot;</span> label=<span style="color: #ff0000;">&quot;Modify Styles&quot;</span> click=<span style="color: #ff0000;">&quot;modifyStyleValue( )&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;mergedButton&quot;</span>  label=<span style="color: #ff0000;">&quot;Modify Merged Styles&quot;</span> click=<span style="color: #ff0000;">&quot;modifyMergedStyleValue( )&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Module</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

</blockquote>
<p>The module code above tries to modify the styles (color, and borderColor) for the spark List. You can use the color picker to pick in the new color. If you press the &#8220;Modify Styles&#8221; button, the style values will get updated because modifyStyleValue() method obtains CSSStyleDeclaration via the getStyleDeclaration() method.<br />
But if you press the &#8220;Modify Merged Styles&#8221; button, the setStyle() calls will fail silentely because CSSStyleDeclaration (in modifyMergedStyleValue) is obtained via getMergedStyleDeclaration().</p>
<p>Here is the running swf:<br />
<center><br />
<iframe src ="http://gauravj.com/blog/examples/Styles/PerModuleStyles_2/ModifyCSSDeclarationApp.html" width="400" height="400"></p>
<p>Your browser does not support iframes.</p>
<p></iframe><br />
</center><br />
Also notice that when you press the &#8220;Modify Styles&#8221; button, only the styles of the spark list in the module will get updated. Why? It&#8217;s because the module is using the instance of StyleManager (myStyleManager) obtained using getStyleManager() (by passing the current module factory &#8211; this.moduleFactory). So this instance is different that the top level style manager which the main app is using. </p>
]]></content:encoded>
			<wfw:commentRss>http://gauravj.com/blog/2010/02/stylemanager-in-flex-4/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Stylish modules and sub applications.</title>
		<link>http://gauravj.com/blog/2010/02/stylish-modules-and-sub-applications/</link>
		<comments>http://gauravj.com/blog/2010/02/stylish-modules-and-sub-applications/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 15:35:19 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[Flex Framework]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[Styles]]></category>

		<guid isPermaLink="false">http://gauravj.com/blog/?p=616</guid>
		<description><![CDATA[<p>One of the features that&#8217;s coming with Flex 4 is &#8220;Per-Module Style Management&#8221;. There is a lot that can be written about this feature and it probably can&#8217;t be covered in a single post. So for starters here is a small introduction.</p>
<p>The feature for Per-Module Style Management was done to allow modules and sub applications to <span style="color:#777"> . . . &#8594; Read More: <a href="http://gauravj.com/blog/2010/02/stylish-modules-and-sub-applications/">Stylish modules and sub applications.</a></span>]]></description>
			<content:encoded><![CDATA[<p>One of the features that&#8217;s coming with Flex 4 is &#8220;Per-Module Style Management&#8221;. There is a lot that can be written about this feature and it probably can&#8217;t be covered in a single post. So for starters here is a small introduction.</p>
<p>The feature for Per-Module Style Management was done to allow modules and sub applications to be able to manage their own styles. With this feature StyleManager will no longer be a singleton and as a result that will allow modules and sub applications to have their own instances of StyleManager. </p>
<p>Modules and sub applications will continue to inherit styles from the parent application/module. But only the style properties not defined by the child modules or sub applications will trickle down (i.e. child module/application will be able to override a style property defined by the parent). There will also be merging of styles properties. </p>
<p>To understand this better, lets take a look at a sample. Following is the code for a parent application:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Application</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">			   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #000000;">			   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> minWidth=<span style="color: #ff0000;">&quot;1024&quot;</span> minHeight=<span style="color: #ff0000;">&quot;768&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;application1_creationCompleteHandler(event)&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Style</span><span style="color: #7400FF;">&gt;</span></span>
		@namespace s &quot;library://ns.adobe.com/flex/spark&quot;;
		@namespace mx &quot;library://ns.adobe.com/flex/mx&quot;;
&nbsp;
		global {
			chromeColor: #DDAA66;	
		}
&nbsp;
		s|DropDownList
		{
			fontStyle: italic;
		}
&nbsp;
		s|Button#gumboButton
		{
			fontStyle: italic;
		}
&nbsp;
		s|Panel s|Label
		{
			fontStyle: italic;
		}
&nbsp;
		s|Button.myStyle
		{
			fontStyle: italic;
		}
&nbsp;
		s|HGroup s|RichText
		{
			fontStyle: italic;
		}
&nbsp;
		.classOfStyle
		{
			fontStyle: italic;
		}
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Style</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">			import mx.events.FlexEvent;</span>
<span style="color: #000000;">			import mx.collections.ArrayList;</span>
<span style="color: #000000;">			import mx.events.ModuleEvent;</span>
<span style="color: #000000;">			import mx.events.StyleEvent;</span>
<span style="color: #000000;">			import mx.controls.Alert;</span>
&nbsp;
<span style="color: #000000;">			private var arr:Array =</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Apple'</span>, data:<span style="color: #cc66cc;">10.00</span><span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Banana'</span>, data:<span style="color: #cc66cc;">15.00</span> <span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Melon'</span>, data:<span style="color: #cc66cc;">3.50</span> <span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Kiwi'</span>, data:<span style="color: #cc66cc;">7.65</span><span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Strawberry'</span>,data:<span style="color: #cc66cc;">12.35</span> <span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Other'</span>, data:<span style="color: #cc66cc;">00.00</span><span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#93;</span>;</span>
&nbsp;
<span style="color: #000000;">			private var listArr :ArrayList = new ArrayList<span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#41;</span>;</span>
&nbsp;
<span style="color: #000000;">			protected function application1_creationCompleteHandler<span style="color: #66cc66;">&#40;</span>event:FlexEvent<span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				appList.dataProvider = listArr;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			public function load<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				if<span style="color: #66cc66;">&#40;</span>mod_loader.url == null<span style="color: #66cc66;">&#41;</span></span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">					mod_loader.url = <span style="color: #ff0000;">&quot;LoadStylesModule.swf&quot;</span>;	</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">				else</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">					mod_loader.loadModule<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			public function unload<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				mod_loader.unloadModule<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VerticalLayout</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VGroup</span> id=<span style="color: #ff0000;">&quot;groupId&quot;</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VGroup</span> <span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:CheckBox</span> id=<span style="color: #ff0000;">&quot;checkBox&quot;</span> label=<span style="color: #ff0000;">&quot;Check Box&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;Label Outside Panel&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:VGroup</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HGroup</span> rotation=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:NumericStepper</span> id=<span style="color: #ff0000;">&quot;numericStepper&quot;</span> stepSize=<span style="color: #ff0000;">&quot;1&quot;</span> minimum=<span style="color: #ff0000;">&quot;1&quot;</span> maximum=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:RichText</span> text=<span style="color: #ff0000;">&quot;This Text is Rich !!&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:RichText</span> text=<span style="color: #ff0000;">&quot;This Text is also Rich !!&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Panel</span> title=<span style="color: #ff0000;">&quot;Gumbo Panel&quot;</span> id=<span style="color: #ff0000;">&quot;appPanel&quot;</span> rotation=<span style="color: #ff0000;">&quot;-5&quot;</span><span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span><span style="color: #7400FF;">&gt;</span></span>
					<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VerticalLayout</span> <span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span><span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;gumboButton&quot;</span> label=<span style="color: #ff0000;">&quot;Gumbo Button&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;gumboButton2&quot;</span> label=<span style="color: #ff0000;">&quot;Second Gumbo Button&quot;</span> styleName=<span style="color: #ff0000;">&quot;myStyle&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;Spark Label&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;Spark Label class selector&quot;</span> styleName=<span style="color: #ff0000;">&quot;classOfStyle&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:DropDownList</span> id=<span style="color: #ff0000;">&quot;appList&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Panel</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:VGroup</span><span style="color: #7400FF;">&gt;</span></span>	
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ModuleLoader</span> id=<span style="color: #ff0000;">&quot;mod_loader&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> label=<span style="color: #ff0000;">&quot;Load Module&quot;</span> click=<span style="color: #ff0000;">&quot;load()&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> label=<span style="color: #ff0000;">&quot;Unload Module&quot;</span> click=<span style="color: #ff0000;">&quot;unload()&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

</blockquote>
<p>If you notice, the above code defines a bunch of styles. It sets the chrome color to DDAA66 in the global selector and it sets the fontStyle to italic using various selectors (class, Id, Type, descendant).</p>
<p>Now let&#8217;s take a look at the code of the module (LoadStylesModule.mxml):</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Module</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">		   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #000000;">		   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;module1_creationCompleteHandler(event)&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">			import mx.collections.ArrayList;</span>
<span style="color: #000000;">			import mx.controls.Alert;</span>
<span style="color: #000000;">			import mx.events.FlexEvent;</span>
<span style="color: #000000;">			import mx.events.StyleEvent;</span>
&nbsp;
<span style="color: #000000;">			private var arr:Array =</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Apple'</span>, data:<span style="color: #cc66cc;">10.00</span><span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Banana'</span>, data:<span style="color: #cc66cc;">15.00</span> <span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Melon'</span>, data:<span style="color: #cc66cc;">3.50</span> <span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Kiwi'</span>, data:<span style="color: #cc66cc;">7.65</span><span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Strawberry'</span>,data:<span style="color: #cc66cc;">12.35</span> <span style="color: #66cc66;">&#125;</span>,</span>
<span style="color: #000000;">					<span style="color: #66cc66;">&#123;</span> label:<span style="color: #ff0000;">'Other'</span>, data:<span style="color: #cc66cc;">00.00</span><span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#93;</span>;</span>
&nbsp;
<span style="color: #000000;">			private var listArr :ArrayList = new ArrayList<span style="color: #66cc66;">&#40;</span>arr<span style="color: #66cc66;">&#41;</span>;</span>
&nbsp;
<span style="color: #000000;">			protected function module1_creationCompleteHandler<span style="color: #66cc66;">&#40;</span>event:FlexEvent<span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				moduleList.dataProvider = listArr;</span>
<span style="color: #000000;">				localStyleManager  = StyleManager.getStyleManager<span style="color: #66cc66;">&#40;</span>this.moduleFactory<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			private var localStyleManager:IStyleManager2 = null;</span>
&nbsp;
<span style="color: #000000;">			public var eventDispatcher:IEventDispatcher = null;</span>
<span style="color: #000000;">			protected function loadStylesButton_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
&nbsp;
<span style="color: #000000;">				eventDispatcher = localStyleManager.loadStyleDeclarations<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;testStyles.swf&quot;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			protected function unloadStylesButton_clickHandler<span style="color: #66cc66;">&#40;</span>event:MouseEvent<span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				localStyleManager.unloadStyleDeclarations<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;testStyles.swf&quot;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VGroup</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:CheckBox</span> id=<span style="color: #ff0000;">&quot;checkBox&quot;</span> label=<span style="color: #ff0000;">&quot;Check Box Module&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;Label Outside Panel&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HGroup</span> rotation=<span style="color: #ff0000;">&quot;-10&quot;</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:NumericStepper</span> id=<span style="color: #ff0000;">&quot;numericStepper&quot;</span> stepSize=<span style="color: #ff0000;">&quot;1&quot;</span> minimum=<span style="color: #ff0000;">&quot;1&quot;</span> maximum=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:RichText</span> text=<span style="color: #ff0000;">&quot;This Text is Rich Module !!&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:RichText</span> text=<span style="color: #ff0000;">&quot;This Text is also Rich !!&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Panel</span> title=<span style="color: #ff0000;">&quot;Gumbo Module Panel&quot;</span> id=<span style="color: #ff0000;">&quot;appPanel&quot;</span> rotation=<span style="color: #ff0000;">&quot;-5&quot;</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:layout</span><span style="color: #7400FF;">&gt;</span></span>
				<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VerticalLayout</span> <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:layout</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;gumboButton&quot;</span> label=<span style="color: #ff0000;">&quot;Gumbo Module Button&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Button</span> id=<span style="color: #ff0000;">&quot;gumboButton2&quot;</span> label=<span style="color: #ff0000;">&quot;Second Gumbo Module Button&quot;</span> styleName=<span style="color: #ff0000;">&quot;myStyle&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;Spark Module Label&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;Spark Label Module class selector&quot;</span> styleName=<span style="color: #ff0000;">&quot;classOfStyle&quot;</span>  <span style="color: #7400FF;">/&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:ComboBox</span> id=<span style="color: #ff0000;">&quot;moduleList&quot;</span> height=<span style="color: #ff0000;">&quot;24&quot;</span> width=<span style="color: #ff0000;">&quot;147&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Panel</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:VGroup</span><span style="color: #7400FF;">&gt;</span></span>	
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;Load styles&quot;</span> id=<span style="color: #ff0000;">&quot;loadStylesButton&quot;</span> click=<span style="color: #ff0000;">&quot;loadStylesButton_clickHandler(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;Unload styles&quot;</span> id=<span style="color: #ff0000;">&quot;unloadStylesButton&quot;</span> click=<span style="color: #ff0000;">&quot;unloadStylesButton_clickHandler(event)&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Module</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

</blockquote>
<p>The code for the module above does not define any styles. So what that means is that it will inherit the styles from the parent app. It will have the chrome color of DDAA66 for all components and also the font styles will be italic. So far that&#8217;s all normal and boring stuff. Now you probably also noticed that the module  loads a styles declaration swf (which is a css compiled to a swf), and when you load the styles swf you will see the magic of per-module style management. The module will override style definition for some properties (originally defined in the main app) and for other properties styles merging will happen.</p>
<p>Here is the code for the css (testStyles.css):</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;">@namespace s &quot;library://ns.adobe.com/flex/spark&quot;;
@namespace mx &quot;library://ns.adobe.com/flex/mx&quot;;
&nbsp;
s|DropDownList
{
	borderColor: #FF0000;
	fontSize: 16;
}
&nbsp;
s|Button#gumboButton
{
	chromeColor: #AAFFAA;
	fontSize: 16;
}
&nbsp;
s|Panel s|Label
{
	fontSize: 16;
}
&nbsp;
s|Button.myStyle
{
	chromeColor: #FFFFAA;
	fontSize: 14;
}
&nbsp;
s|HGroup s|RichText
{
	chromeColor: #BBAAAA;
	fontSize: 14;
}
&nbsp;
.classOfStyle
{
	color: #0FFFFA;	
	fontSize: 20;
}</pre></div></div>

</blockquote>
<p>Here is the running swf:<br />
<center><br />
<iframe src ="http://gauravj.com/blog/examples/Styles/PerModuleStyles_1/StylesApp.html" width="700" height="400"></p>
<p>Your browser does not support iframes.</p>
<p></iframe><br />
</center></p>
<p>Click on the &#8220;Load Module&#8221; button to load the module. Once the module is loaded, notice the chrome color of most components is the same as in the parent app and the font is italicized for most components &#8211; this shows that the module inherits styles from the parent app. Now click on the &#8220;Load styles&#8221; button in the module, once the styles swf is loaded you can notice that the font size changes for most components but the fonts in the module are still italicized &#8211; this shows styles merging because we were only overriding the fontSize in the css and not the fontStyle property. Also notice the new chrome color for components in the module, its now different from the global chrome color (DDAA66). So the module is able to override the styles properties it chooses.</p>
<p>So, hopefully you find this short introduction useful. Stay tuned for more on this.. And if you want me to write about something else, please say so with your comments (which btw are welcome <img src='http://gauravj.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  )</p>
]]></content:encoded>
			<wfw:commentRss>http://gauravj.com/blog/2010/02/stylish-modules-and-sub-applications/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>New and Improved Flex 3.5 build</title>
		<link>http://gauravj.com/blog/2010/02/new-and-improved-flex-3-5-build/</link>
		<comments>http://gauravj.com/blog/2010/02/new-and-improved-flex-3-5-build/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 03:41:02 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://gauravj.com/blog/?p=607</guid>
		<description><![CDATA[<p>If you have been using Flex 3.5, you might want to upgrade to Flex 3.5a. Yes, the &#8216;a&#8217; after 3.5 is not a typo. The Flex 3.5 build has been updated to address an issue with Flex-based AIR auto-update UI packaged within the SDK. The related JIRA bug for issue is http://bugs.adobe.com/jira/browse/SDK-24766</p>
<p>All developers using Flex 3.5 <span style="color:#777"> . . . &#8594; Read More: <a href="http://gauravj.com/blog/2010/02/new-and-improved-flex-3-5-build/">New and Improved Flex 3.5 build</a></span>]]></description>
			<content:encoded><![CDATA[<p>If you have been using Flex 3.5, you might want to upgrade to Flex 3.5a. Yes, the &#8216;a&#8217; after 3.5 is not a typo. The Flex 3.5 build has been updated to address an issue with Flex-based AIR auto-update UI packaged within the SDK. The related JIRA bug for issue is <a href="http://bugs.adobe.com/jira/browse/SDK-24766">http://bugs.adobe.com/jira/browse/SDK-24766</a></p>
<p>All developers using Flex 3.5 are encouraged to upgrade to Flex 3.5a. You can download this new build from <a href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3">http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3</a></p>
<p>Also if you are using a Flex build older than Flex 3.5 then you are definitely encouraged to upgrade and try the latest builds. The milestone builds contain many bug fixes.. </p>
<p>We are always interested in hearing from you, regarding the feedback. Also if you run into any bugs you can log them at <a href="http://bugs.adobe.com/jira">http://bugs.adobe.com/jira</a></p>
]]></content:encoded>
			<wfw:commentRss>http://gauravj.com/blog/2010/02/new-and-improved-flex-3-5-build/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating SWC files with asdoc comments..</title>
		<link>http://gauravj.com/blog/2010/01/creating-swc-files-with-asdoc-comments/</link>
		<comments>http://gauravj.com/blog/2010/01/creating-swc-files-with-asdoc-comments/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 06:36:28 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[Flex Tools]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[ASDoc]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[SWC]]></category>

		<guid isPermaLink="false">http://gauravj.com/blog/?p=572</guid>
		<description><![CDATA[<p>Have you tried the latest Flash Builder? If not, the latest beta can be downloaded from http://labs.adobe.com/technologies/flashbuilder4/?sdid=EUHSU</p>
<p>But if you have already tried it, you would have noticed that now ActionScript and MXML editors show ASDoc documentation when you hover over variables/method/class names. See screen shot below:
</p>
<p>This means that you can now see the documentation as you <span style="color:#777"> . . . &#8594; Read More: <a href="http://gauravj.com/blog/2010/01/creating-swc-files-with-asdoc-comments/">Creating SWC files with asdoc comments..</a></span>]]></description>
			<content:encoded><![CDATA[<p>Have you tried the latest Flash Builder? If not, the latest beta can be downloaded from <a href="http://labs.adobe.com/technologies/flashbuilder4/?sdid=EUHSU">http://labs.adobe.com/technologies/flashbuilder4/?sdid=EUHSU</a></p>
<p>But if you have already tried it, you would have noticed that now ActionScript and MXML editors show ASDoc documentation when you hover over variables/method/class names. See screen shot below:<br />
<img src="examples/ASDoc/FlashBuilder_ASDoc_Help.png" /></p>
<p>This means that you can now see the documentation as you are writing code. You can see the method/variable signature or any other documentation associated with any of the class elements. And for all this you don&#8217;t need to open the language reference in a separate browser window or search for the documentation.</p>
<p>Behind the scenes Flash Builder pulls this information from the Flex SDK swc files and the ASDoc info is stored in XML files inside the SWC files. For all nightly builds of Flex SDK, the swcs will come with these ASDoc XML files. In case you want to add similar ASDoc XML files to your custom swcs, you can do that too. Currently there is no single command to generate swc with ASDoc XML files, it is done in three simple steps. And the three steps are:</p>
<ol>
<li>Generate SWC</li>
<li>Generate doc XML Files using ASDoc tool</li>
<li>Update SWC with doc XML fIles</li>
</ol>
<p>I hope you already know how to generate a swc file. If not, take a look at <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_22.html">http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_22.html</a><br />
In order to generate the doc XML files using ASDoc tool, you will have to run the asdoc tool using <strong>-keep-xml=true</strong> and <strong>-skip-xsl=true</strong><br />
A swc file is a compressed file, so to update it (with doc XML files) you can simply use a zip command. </p>
<p>For reference, you can also look at the build.xml file in the framework project of the Flex SDK. Following is the &#8220;doc&#8221; target which performs step #2 and #3:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;target name=<span style="color: #ff0000;">&quot;doc&quot;</span> depends=<span style="color: #ff0000;">&quot;clean-temp-docs&quot;</span> description=<span style="color: #ff0000;">&quot;updates framework.swc with asdoc xml&quot;</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Load the &lt;asdoc&gt;</span></span> task. We can't do this at the <span style="color: #000000;">&lt;project<span style="color: #7400FF;">&gt;</span></span> level --&gt;
		<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- because targets that run before flexTasks.jar gets built would fail. --&gt;</span></span>
		<span style="color: #000000;">&lt;taskdef resource=<span style="color: #ff0000;">&quot;flexTasks.tasks&quot;</span> classpath=<span style="color: #ff0000;">&quot;${FLEX_HOME}/lib/flexTasks.jar&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
	    <span style="color: #000000;">&lt;condition property=<span style="color: #ff0000;">&quot;asdoc.jvm.args&quot;</span> value=<span style="color: #ff0000;">&quot;-Xmx384m&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	        <span style="color: #000000;">&lt;os family=<span style="color: #ff0000;">&quot;windows&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	    <span style="color: #000000;">&lt;/condition<span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	    <span style="color: #000000;">&lt;condition property=<span style="color: #ff0000;">&quot;asdoc.jvm.args&quot;</span> value=<span style="color: #ff0000;">&quot;-Xmx512m&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	        <span style="color: #000000;">&lt;os family=<span style="color: #ff0000;">&quot;mac&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	    <span style="color: #000000;">&lt;/condition<span style="color: #7400FF;">&gt;</span></span>
&nbsp;
	    <span style="color: #000000;">&lt;condition property=<span style="color: #ff0000;">&quot;asdoc.jvm.args&quot;</span> value=<span style="color: #ff0000;">&quot;-Xmx512m&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	        <span style="color: #000000;">&lt;os family=<span style="color: #ff0000;">&quot;unix&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	    <span style="color: #000000;">&lt;/condition<span style="color: #7400FF;">&gt;</span></span>
&nbsp;
		<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Call asdoc to generate dita xml files --&gt;</span></span>
		<span style="color: #000000;">&lt;asdoc output=<span style="color: #ff0000;">&quot;${FLEX_HOME}/tempDoc&quot;</span> lenient=<span style="color: #ff0000;">&quot;true&quot;</span> failonerror=<span style="color: #ff0000;">&quot;true&quot;</span> keep-xml=<span style="color: #ff0000;">&quot;true&quot;</span> skip-xsl=<span style="color: #ff0000;">&quot;true&quot;</span> fork=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #7400FF;">&gt;</span></span>
		    <span style="color: #000000;">&lt;compiler.source-path path-element=<span style="color: #ff0000;">&quot;${basedir}/src&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		    <span style="color: #000000;">&lt;doc-classes class=<span style="color: #ff0000;">&quot;FrameworkClasses&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		    <span style="color: #000000;">&lt;doc-namespaces uri=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		    <span style="color: #000000;">&lt;namespace uri=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> manifest=<span style="color: #ff0000;">&quot;${basedir}/manifest.xml&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		    <span style="color: #000000;">&lt;jvmarg line=<span style="color: #ff0000;">&quot;${asdoc.jvm.args}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;">&lt;/asdoc<span style="color: #7400FF;">&gt;</span></span>
&nbsp;
		<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- updates framework.swc with asdoc xml --&gt;</span></span>
		<span style="color: #000000;">&lt;zip destfile=<span style="color: #ff0000;">&quot;${FLEX_HOME}/frameworks/locale/en_US/framework_rb.swc&quot;</span> update=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #7400FF;">&gt;</span></span>
		    <span style="color: #000000;">&lt;zipfileset dir=<span style="color: #ff0000;">&quot;${FLEX_HOME}/tempDoc/tempdita&quot;</span> prefix=<span style="color: #ff0000;">&quot;docs&quot;</span><span style="color: #7400FF;">&gt;</span></span>
			    <span style="color: #000000;">&lt;include name=<span style="color: #ff0000;">&quot;*.*&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;">&lt;exclude name=<span style="color: #ff0000;">&quot;ASDoc_Config.xml&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
				<span style="color: #000000;">&lt;exclude name=<span style="color: #ff0000;">&quot;overviews.xml&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		    <span style="color: #000000;">&lt;/zipfileset<span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;">&lt;/zip<span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;">&lt;/target<span style="color: #7400FF;">&gt;</span></span></pre></div></div>

</blockquote>
<p>So give it a try, and if you find any bugs you can log them at <a href="http://bugs.adobe.com/flex">http://bugs.adobe.com/flex</a></p>
]]></content:encoded>
			<wfw:commentRss>http://gauravj.com/blog/2010/01/creating-swc-files-with-asdoc-comments/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
