<?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; TitleWindow</title>
	<atom:link href="http://gauravj.com/blog/tag/titlewindow/feed/" rel="self" type="application/rss+xml" />
	<link>http://gauravj.com/blog</link>
	<description>Tips and Tools of Flex</description>
	<lastBuildDate>Wed, 28 Mar 2012 17:55:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</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[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>14</slash:comments>
		</item>
	</channel>
</rss>

