<?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; Flex Framework</title>
	<atom:link href="http://gauravj.com/blog/category/framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://gauravj.com/blog</link>
	<description>Tips and Tools of Flex</description>
	<lastBuildDate>Thu, 21 Apr 2011 20:05:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Using spark datagrid to capture multiple rows of data</title>
		<link>http://gauravj.com/blog/2011/04/using-spark-datagrid-to-capture-multiple-rows-of-data/</link>
		<comments>http://gauravj.com/blog/2011/04/using-spark-datagrid-to-capture-multiple-rows-of-data/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 20:05:59 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[Flex Framework]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[Editor]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[Item Renderer]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[Skins]]></category>
		<category><![CDATA[Spark]]></category>

		<guid isPermaLink="false">http://gauravj.com/blog/?p=948</guid>
		<description><![CDATA[<p>Sometimes you need forms to capture entries for multiple rows of data. In such forms each row is a sub object (with multiple associated parameters), like sales report for a particular item or a particular expense in an expense report. The tricky part with such forms is that you can&#8217;t predict how many sub <span style="color:#777"> . . . &#8594; Read More: <a href="http://gauravj.com/blog/2011/04/using-spark-datagrid-to-capture-multiple-rows-of-data/">Using spark datagrid to capture multiple rows of data</a></span>]]></description>
			<content:encoded><![CDATA[<p>Sometimes you need forms to capture entries for multiple rows of data. In such forms each row is a sub object (with multiple associated parameters), like sales report for a particular item or a particular expense in an expense report. The tricky part with such forms is that you can&#8217;t predict how many sub objects will be captured, so you need to dynamically add controls to capture data. </p>
<p>To achieve this why not use the spark data grid instead of a form? This way you add a new row to the data grid instead of adding controls for each parameter of sub object.</p>
<p>Lets take a look at an app that captures data for an expense report:<br />
<center><br />
<iframe src ="http://gauravj.com/blog/examples/SparkDataGrid/DataGridFormExample.html" width="900" height="500"></p>
<p>Your browser does not support iframes.</p>
<p></iframe><br />
</center><br />
You can download the fxp file for this project from <a href="http://gauravj.com/blog/examples/SparkDataGrid/DataGridFormExample.fxp">DataGridFormExample.fxp</a></p>
<p>You can click on the trash icon to delete a row. And if you want to add blank rows, then you can either click on the new icon in the top left of the grid or click the <em>TAB</em> key in the comments field of the last row.</p>
<p>I primarily did the following customization to change the look of the datagrid:</p>
<ul>
<li>Custom skin for the datagrid (EntryDGSkin.mxml) to hide all the row and column separators. </li>
<li>Used custom item renderers and marked rendererIsEditable as true so the controls are always visible when the rows are present in the datagrid</li>
</ul>
<p>There are validators defined inside the item renderer and when the validation fails the item renderer changes a boolean property (invalidValue) on the parent document. So before saving, the document checks the boolean value to decide whether to proceed with save or not. If you don&#8217;t like the approach to set a boolean flag, then you can also access each validator via the itemRenderer for a particular cell. To access the itemRender use the getItemRendererAt() method present on grid property inside the spark data grid.</p>
<p>Also you should pay attention to the <strong>prepare()</strong>and <strong>discard()</strong>methods inside the data grid itemRenderers. The <strong>prepare()</strong> method is called for every visual update and it sets the data to the sub component of item renderer. I am using a boolean flag (pendingEdits &#8211; set to false when there are unsaved changes) inside the itemRenderers to decide whether to update the sub component or not.</p>
<p>Spark datagrid is a new feature in Flex SDK 4.5 and to import the fxp file you would need Flash Builder 4.5.<br />
Both Flex SDK 4.5 and Flash Builder 4.5 were announced recently. See <a href="http://blogs.adobe.com/flex/2011/04/announcing-flex-sdk-4-5-flash-builder-4-5-and-flash-catalyst-cs-5-5.html">the flex team blog</a></p>
<p>Feedback is welcome <img src='http://gauravj.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://gauravj.com/blog/2011/04/using-spark-datagrid-to-capture-multiple-rows-of-data/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting icon on spark button</title>
		<link>http://gauravj.com/blog/2011/01/setting-icon-on-spark-button/</link>
		<comments>http://gauravj.com/blog/2011/01/setting-icon-on-spark-button/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 23:45:02 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[Flex Framework]]></category>
		<category><![CDATA[Button]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[Styles]]></category>

		<guid isPermaLink="false">http://gauravj.com/blog/?p=883</guid>
		<description><![CDATA[<p>A friend asked why the spark button doesn&#8217;t support icons like the mx button? Well now it does with the upcoming hero release. </p> <p>Here a quick example:</p> &#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62; &#60;s:Application xmlns:fx=&#34;http://ns.adobe.com/mxml/2009&#34; xmlns:s=&#34;library://ns.adobe.com/flex/spark&#34; xmlns:mx=&#34;library://ns.adobe.com/flex/mx&#34; minWidth=&#34;955&#34; minHeight=&#34;600&#34;&#62; &#60;fx:Declarations&#62; &#60;s:RadioButtonGroup id=&#34;rbg&#34;/&#62; &#60;/fx:Declarations&#62; &#60;s:layout&#62; &#60;s:VerticalLayout paddingLeft=&#34;5&#34; paddingRight=&#34;5&#34; /&#62; &#60;/s:layout&#62; &#60;s:HGroup&#62; &#60;s:RadioButton label=&#34;left&#34; value=&#34;left&#34; group=&#34;{rbg}&#34; selected=&#34;true&#34;/&#62; &#60;s:RadioButton <span style="color:#777"> . . . &#8594; Read More: <a href="http://gauravj.com/blog/2011/01/setting-icon-on-spark-button/">Setting icon on spark button</a></span>]]></description>
			<content:encoded><![CDATA[<p>A friend asked why the spark button doesn&#8217;t support icons like the mx button?<br />
Well now it does with the upcoming <a href="http://opensource.adobe.com/wiki/display/flexsdk/Hero">hero</a> release. </p>
<p>Here a quick example:</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> minWidth=<span style="color: #ff0000;">&quot;955&quot;</span> minHeight=<span style="color: #ff0000;">&quot;600&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Declarations</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:RadioButtonGroup</span> id=<span style="color: #ff0000;">&quot;rbg&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Declarations</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> paddingLeft=<span style="color: #ff0000;">&quot;5&quot;</span> paddingRight=<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:RadioButton</span> label=<span style="color: #ff0000;">&quot;left&quot;</span> value=<span style="color: #ff0000;">&quot;left&quot;</span> group=<span style="color: #ff0000;">&quot;{rbg}&quot;</span> selected=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:RadioButton</span> label=<span style="color: #ff0000;">&quot;right&quot;</span> value=<span style="color: #ff0000;">&quot;right&quot;</span> group=<span style="color: #ff0000;">&quot;{rbg}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:RadioButton</span> label=<span style="color: #ff0000;">&quot;top&quot;</span> value=<span style="color: #ff0000;">&quot;top&quot;</span> group=<span style="color: #ff0000;">&quot;{rbg}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:RadioButton</span> label=<span style="color: #ff0000;">&quot;bottom&quot;</span> value=<span style="color: #ff0000;">&quot;bottom&quot;</span> group=<span style="color: #ff0000;">&quot;{rbg}&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> id=<span style="color: #ff0000;">&quot;myButton&quot;</span> label=<span style="color: #ff0000;">&quot;Button with Icon&quot;</span> icon=<span style="color: #ff0000;">&quot;@Embed(source='Fx.png')&quot;</span> iconPlacement=<span style="color: #ff0000;">&quot;{rbg.selectedValue}&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><center><br />
<iframe src ="http://gauravj.com/blog/examples/Styles/ButtonIcon/ButtonIconExample.html" width="250" height="100"></p>
<p>Your browser does not support iframes.</p>
<p></iframe><br />
</center></p>
]]></content:encoded>
			<wfw:commentRss>http://gauravj.com/blog/2011/01/setting-icon-on-spark-button/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RSL enhancements in Hero</title>
		<link>http://gauravj.com/blog/2011/01/rsl-enhancement-in-hero/</link>
		<comments>http://gauravj.com/blog/2011/01/rsl-enhancement-in-hero/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 17:04:13 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[Flex Framework]]></category>
		<category><![CDATA[Flex Tools]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[RSL]]></category>

		<guid isPermaLink="false">http://gauravj.com/blog/?p=830</guid>
		<description><![CDATA[<p>While RSLs help to reduce the size for your Flex applications, they can sometimes be tricky to use. So to simplify the usage of RSLs, we made some enhancements in the upcoming Flex SDK release (code-named Hero).</p> <p>These enhancements should provide the following benefits:</p> Applications will only load RSLs that are required Modules (and <span style="color:#777"> . . . &#8594; Read More: <a href="http://gauravj.com/blog/2011/01/rsl-enhancement-in-hero/">RSL enhancements in Hero</a></span>]]></description>
			<content:encoded><![CDATA[<p>While RSLs help to reduce the size for your Flex applications, they can sometimes be tricky to use. So to simplify the usage of RSLs, we made some enhancements in the upcoming Flex SDK release (code-named <a href="http://opensource.adobe.com/wiki/display/flexsdk/Hero">Hero</a>).</p>
<p>These enhancements should provide the following benefits:</p>
<ul>
<li>Applications will only load RSLs that are required</li>
<li>Modules (and sub applications) will use RSLs which are already loaded by the parent application (or module)</li>
<li>Enable sharing of RSLs between modules (and sub applications)</li>
<li>Simply usage of Monkey Patch with Flex RSLs</li>
</ul>
<h3>Only load what&#8217;s needed</h3>
<p>In Flex 4, all RSLs that were listed in the flex-config.xml (at compile time) were loaded by the app when it was launched. But with the Hero release the compiler will remove any RSLs which are not needed by your application. This means that the load time for your app should improve because it won&#8217;t load any extra RSL. The RSLs removed by the compiler will be the placeholder RSLs. This feature is controlled by a new compiler switch called <strong>-remove-unused-rsls</strong> which defaults to true.</p>
<p>Also if you compile your app using the command line compiler, then it will print the names of the RSLs that are needed by your application. The following is an example of compiler output where the app uses 3 out of the 10 RSLs listed in flex-config.xml<br />
<img alt="" src="http://www.gauravj.com/blog/examples/RSLs/RSL_feedback.png" title="RSL_feedback.png" class="aligncenter" width="803" height="72" /></p>
<p>There could be cases where the compiler may remove RSL which is needed by your app (say if you used soft-linking to load classes from a swc). If you run into such a situation then you can override the compiler&#8217;s decision, to remove the RSL, by using the <strong>-force-rsls</strong> compiler switch. This option takes the path of the swcs for which the RSLs should be force loaded.</p>
<h3>Use what&#8217;s already loaded</h3>
<p>Starting with Hero, modules and sub-applications will use the RSLs loaded by the parent app instead of loading a duplicate copy. </p>
<p>When a module or sub-application loads a new RSL, the RSL will be loaded into the default application domain and if this was the placeholder RSL for the parent app then it will be loaded into the parent&#8217;s application domain. Now if the parent app loads another module or sub-app which needs the same RSL then it will be able to use the RSL loaded by previous module or sub app.</p>
<p>The image below is an example of application where the OSMF RSL is removed by the compiler and so it becomes the placeholder RSL for the main app.<br />
<img alt="" src="http://www.gauravj.com/blog/examples/RSLs/placeholder.png" title="placeholder" class="aligncenter" width="269" height="228" /></p>
<p>In the following image, the main app loads a module that uses spark video player. The module needs OSMF RSL so it loads it into the app domain of the parent application because OSMF RSL is a placeholder RSL. The module does not load the Framework or Spark RSLs because those were already loaded by the parent app.<br />
<img alt="" src="http://www.gauravj.com/blog/examples/RSLs/moduleLoadsRSL.png" title="module loads RSL" class="aligncenter" width="269" height="230" /></p>
<p>Now if the main app loads another sub app which needs OSMF RSL, then the sub-app will simply be able to use the OSMF RSL loaded by the module. </p>
<p>You can also specify the application domain where the module should load the RSL. The <strong>-application-domain</strong> compiler option takes the path of the swc and then the name of the application domain. The valid values for application domain  are &#8216;current&#8217;, &#8216;default&#8217;, &#8216;parent&#8217;, or &#8216;top-level&#8217;</p>
<h3>Smaller Framework RSL</h3>
<p>In Hero, we also reduced the size of the framework RSL. This was done by removing all mx components from framework.swc and moving them to a separate swc called mx.swc. So if you are creating pure spark apps then you don&#8217;t need to load any mx classes. </p>
<h3>Monkey Patch RSL</h3>
<p>The only way to use monkey patches with Flex RSLs is to load monkey patched file as RSL itself. But again it was quite tedious to create a monkey patched RSL, so to simplify that a new compiler option (called <strong>-include-inheritance-dependencies-only</strong>) was added. This option can be used when compiling the monkey patched library. This options works with -include-classes flag and it only pulls dependencies which are of type inheritance. An example for usage of this option: </p>
<p><code>bin/compc -include-classes=spark.components.Button -sp=frameworks/projects/spark/src/ -include-inheritance-dependencies-only=true -output=patch.swc</code></p>
<p>In the above example, the output swc will contain spark.components.Button and only it&#8217;s inheritance dependencies. And the library.swf contained in the output swc can be used as an RSL if you were to monkey patch the spark button component.</p>
<p>Most of these changes (except for the -application-domain compiler option) are already available in the latest <a href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+Hero">Hero preview build</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://gauravj.com/blog/2011/01/rsl-enhancement-in-hero/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<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[examples]]></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 <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>11</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[examples]]></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 <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>7</slash:comments>
		</item>
	</channel>
</rss>

