<?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>Darrell Loverin</title>
	<atom:link href="http://blogs.adobe.com/dloverin/feed" rel="self" type="application/rss+xml" />
	<link>http://blogs.adobe.com/dloverin</link>
	<description>Tips on using the Flex SDK</description>
	<lastBuildDate>Fri, 06 May 2011 20:58:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Single Click Cell Editing and More</title>
		<link>http://blogs.adobe.com/dloverin/2011/05/single-click-editing-and-more.html</link>
		<comments>http://blogs.adobe.com/dloverin/2011/05/single-click-editing-and-more.html#comments</comments>
		<pubDate>Fri, 06 May 2011 20:53:50 +0000</pubDate>
		<dc:creator>dloverin</dc:creator>
				<category><![CDATA[DataGrid]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/dloverin/?p=62</guid>
		<description><![CDATA[The Spark DataGrid starts cell editing when a selected cell is clicked. But what if you want your DataGrid to start editing a cell regardless of whether the cell is selected or not? It is pretty easy to do this &#8230; <a href="http://blogs.adobe.com/dloverin/2011/05/single-click-editing-and-more.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The Spark DataGrid starts cell editing when a selected cell is clicked. But what if you want your DataGrid to start editing a cell regardless of whether the cell is selected or not? It is pretty easy to do this by adding a few listeners to the DataGrid. In a future release of the Spark DataGrid we will most likely add a property that will allow you to choose which method is used to start an editor session.</p>
<p><a href="http://blogs.adobe.com/dloverin/files/2011/05/SingleClickCellEditor.zip">Download the project to see how it&#8217;s done.</a></p>
<p>The project also shows show to use the DateField and the ColorPicker as cell editors.</p>
<p><a href="http://blogs.adobe.com/dloverin/files/2011/05/SingleClickCellEditor.swf" target="_blank">Run the application (required Flash Player 10.2 or greater)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/dloverin/2011/05/single-click-editing-and-more.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Using Validators with Spark Cell Editors</title>
		<link>http://blogs.adobe.com/dloverin/2011/05/using-validators-with-spark-cell-editors.html</link>
		<comments>http://blogs.adobe.com/dloverin/2011/05/using-validators-with-spark-cell-editors.html#comments</comments>
		<pubDate>Fri, 06 May 2011 17:09:46 +0000</pubDate>
		<dc:creator>dloverin</dc:creator>
				<category><![CDATA[DataGrid]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/dloverin/?p=51</guid>
		<description><![CDATA[At some point you will probably want to add a validator to a cell editor. This post shows how to use a validator with Spark cell editors. The Spark DataGrid contains two built-in cell editors, DefaultGridItemEditor and ComboBoxGridItemEditor, both of &#8230; <a href="http://blogs.adobe.com/dloverin/2011/05/using-validators-with-spark-cell-editors.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>At some point you will probably want to add a validator to a cell editor. This post shows how to use a validator with Spark cell editors. The Spark DataGrid contains two built-in cell editors, DefaultGridItemEditor and ComboBoxGridItemEditor, both of which extend GridItemEditor. Neither of these editors has a validator so you will want to create your own custom item editor to add validation. As an example I created an editor, NumberGridItemEditor, that uses the Spark number validator to ensure that the entered data is between 0 and 1000, inclusive.</p>
<p>To add a validator to a custom item editor is pretty simple. Just declare the validator and hook it up the input component.</p>
<p><code><br />
&lt;fx:Declarations&gt;</code></p>
<p><code>&lt;s:NumberValidator id="numberValidator" source="{textInput}" property="text"</p>
<p>triggerEvent="keyUp"/&gt;</p>
<p></code></p>
<p><code>&lt;/fx:Declarations&gt;<br />
</code></p>
<p>Since NumberGridItemEditor subclasses GridItemEditor it picks up some built-in support for validators. When the editor’s data is being saved, the GridItemEditor first checks if the data is valid by calling the validate() method. If the data is not valid then the editor won’t try to save it. If the Enter key is used to end the editor session then the editor will remain displayed so the input may be corrected. But if the user clicks away from the editor then the editor session will be cancelled if the data is not valid and therefore cannot be saved. If the default behavior doesn&#8217;t work for you then it can be modified by overriding the validate() and save() methods of GridItemEditor.</p>
<p><a href="http://blogs.adobe.com/dloverin/files/2011/05/CellEditorWithValidator.zip">Download the project</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/dloverin/2011/05/using-validators-with-spark-cell-editors.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Creating Cell Editors for Multiple Data Fields</title>
		<link>http://blogs.adobe.com/dloverin/2011/05/creating-cell-editors-for-multiple-data-fields.html</link>
		<comments>http://blogs.adobe.com/dloverin/2011/05/creating-cell-editors-for-multiple-data-fields.html#comments</comments>
		<pubDate>Thu, 05 May 2011 22:36:07 +0000</pubDate>
		<dc:creator>dloverin</dc:creator>
				<category><![CDATA[DataGrid]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/dloverin/?p=27</guid>
		<description><![CDATA[DataGrid item renderers allow you to display multiple fields in one cell. For example, a name could be displayed in one cell but it may be a combination of two fields, first name and last name. How do you create &#8230; <a href="http://blogs.adobe.com/dloverin/2011/05/creating-cell-editors-for-multiple-data-fields.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>DataGrid item renderers allow you to display multiple fields in one cell. For example, a name could be displayed in one cell but it may be a combination of two fields, first name and last name. How do you create a matching item editor? The key method to override when writing to multiple data fields is GridItemEditor.save().  Normally the save() method updates the data field specified by the GridColumn&#8217;s dataField property. By overriding the save() method you can update as many fields as you want. To see the full source of this editor, <a href="http://blogs.adobe.com/dloverin/files/2011/05/MultiControlPopUpEditor.zip">Download the project files</a> and take a look at FirstLastNamePopUpGridItemEditor.mxml.</p>
<p>One problem you’ll run into when you create an editor for multiple fields is that the editor no longer fits neatly inside the cell. I think the best way to solve this problem is to put the item editor in a pop up so it is not clipped by the DataGrid. In the FirstLastNamePopUpGridItemEditor component this is done declaratively by using the Spark  PopUpAnchor component.</p>
<p>The pop up in the item editor uses the Spark BorderContainer component. This ends up causing the child components in the pop up to get their own FocusManager which implies the focus loop will stay within the pop up. But what I really want is to be able to tab out of the item editor and go to the next item editor, the same way the tab key moves out of any other item editor. This can be done by re-dispatching selective events from the pop up to the item editor.</p>
<p>Another example of using pop ups in an item editor is the TextWithOkCancelGridItemEditor component. This component places OK and Cancel buttons on the right side of the  Spark TextArea component. The TextArea component is sized to the cell so the OK and Cancel buttons need be in a pop up to keep them from being clipped by the DataGrid or the DataGrid’s scrollbar. Adding OK and Cancel buttons can be useful if the TextArea component uses the Enter key to insert a newline in the text instead of ending the editing session. That behavior may confuse some users so providing the OK button will give them clear way to end the editing session.</p>
<p><a href="http://blogs.adobe.com/dloverin/files/2011/05/MultiControlPopUpEditor.swf">Run the application</a> (requires Flash Player 10.2 or greater)</p>
<p><a href="http://blogs.adobe.com/dloverin/files/2011/05/MultiControlPopUpEditor.zip">MultiControlPopUpEditor Project Files</a></p>
<p>The postings on this site are my own and don’t necessarily represent Adobe’s positions, views, strategies or opinions.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/dloverin/2011/05/creating-cell-editors-for-multiple-data-fields.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Spark Grid Item Editors</title>
		<link>http://blogs.adobe.com/dloverin/2011/05/using-spark-grid-item-editors.html</link>
		<comments>http://blogs.adobe.com/dloverin/2011/05/using-spark-grid-item-editors.html#comments</comments>
		<pubDate>Thu, 05 May 2011 17:43:45 +0000</pubDate>
		<dc:creator>dloverin</dc:creator>
				<category><![CDATA[DataGrid]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/dloverin/?p=16</guid>
		<description><![CDATA[This post shows a simple example of using the default item editors in the Spark DataGrid. The example application shows how to use the DefaultGridItemEditor and ComboBoxGridItemEditor. DefaultGridItemEditor is an editor for text. If you don’t specify an editor for &#8230; <a href="http://blogs.adobe.com/dloverin/2011/05/using-spark-grid-item-editors.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>This post shows a simple example of using the default item editors in the Spark DataGrid. The example application shows how to use the DefaultGridItemEditor and ComboBoxGridItemEditor.</p>
<p>DefaultGridItemEditor is an editor for text. If you don’t specify an editor for a grid column, this is the one you will get.</p>
<p>The ComboBoxGridItemEditor was designed to provide a two click editing experience. When a cell is clicked to start an editor session, the combo box will be displayed with its drop-down list open. This allows a single click to choose the item in the down-down list that you want. After the down-down is clicked the combo box choice is saved and the editing session is closed. The result is only two clicks to edit a cell and choose a value.</p>
<p><a href="http://blogs.adobe.com/dloverin/files/2011/05/SimpleCellEditor.zip">Download the project</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/dloverin/2011/05/using-spark-grid-item-editors.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New compiler option to support monkey patching RSLs</title>
		<link>http://blogs.adobe.com/dloverin/2010/03/new_compiler_option_to_support_monkey_patching_rsls.html</link>
		<comments>http://blogs.adobe.com/dloverin/2010/03/new_compiler_option_to_support_monkey_patching_rsls.html#comments</comments>
		<pubDate>Sun, 07 Mar 2010 18:23:49 +0000</pubDate>
		<dc:creator>dloverin</dc:creator>
				<category><![CDATA[RSLs]]></category>
		<category><![CDATA[RSL monkey patch]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/dloverin/2010/03/new_compiler_option_to_support_monkey_patching_rsls.html</guid>
		<description><![CDATA[Setting up the monkey patch RSL took a bit of work. First you needed to create an externs file from a link report. Then you needed to figure out the inheritance dependencies and remove them from the externs file. Wouldn&#8217;t &#8230; <a href="http://blogs.adobe.com/dloverin/2010/03/new_compiler_option_to_support_monkey_patching_rsls.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p class="MsoNormal">Setting up the monkey patch RSL took a bit of work. First<br />
you needed to create an externs file from a link report. Then you needed to<br />
figure out the inheritance dependencies and remove them from the externs file.<br />
Wouldn&#8217;t it be nice to have the compiler to this for you? The compiler knows<br />
what the inheritance dependencies are, right?</p>
<p class="MsoNormal">It turns out that writing the prototype for the new compiler option wasn&#8217;t all that hard. I called the new compiler option &#8220;include-inheritance-dependencies-only&#8221;.<br />
It only works with compc and the -include-classes option. Normally compc<br />
will include all the dependences of classes linked into a swc. But when the new<br />
option is used only the inheritance dependences will be linked in. So the<br />
command to build the RSL swc for the mx.collections.ListCollectionView monkey<br />
patch becomes:</p>
<p class="MsoNormal"><span>compc<br />
-include-classes mx.collections.ListCollectionView -include-inheritance-dependencies-only<br />
-source-path . -output lcv2 -directory</span></p>
<p class="MsoNormal">The new option is just a prototype. It may never see the<br />
light of day. If you think this option would be useful please leave a comment<br />
to let me know.</p>
<p class="MsoNormal">&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/dloverin/2010/03/new_compiler_option_to_support_monkey_patching_rsls.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Monkey Patching ListCollectionView</title>
		<link>http://blogs.adobe.com/dloverin/2010/02/monkey_patching_listcollectionview.html</link>
		<comments>http://blogs.adobe.com/dloverin/2010/02/monkey_patching_listcollectionview.html#comments</comments>
		<pubDate>Mon, 01 Feb 2010 14:41:40 +0000</pubDate>
		<dc:creator>dloverin</dc:creator>
				<category><![CDATA[RSLs]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/dloverin/2010/02/monkey_patching_listcollectionview.html</guid>
		<description><![CDATA[The last in this monkey patch series is mx.collections.ListCollectionView. I was going to skip the write up on monkey patching this class but I had already said I was going to do it and there was one interesting twist along &#8230; <a href="http://blogs.adobe.com/dloverin/2010/02/monkey_patching_listcollectionview.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The last in this monkey patch series is mx.collections.ListCollectionView.<br />
I was going to skip the write up on monkey patching this class but I had already<br />
said I was going to do it and there was one interesting twist along the way. I<br />
chose to demonstrate this class because there was a real world case of it<br />
being monkey patched. I haven&#8217;t actually patched the class myself I&#8217;m just going<br />
to demonstrate how to make a patch work when using RSLs.</p>
<p class="MsoNormal">This monkey patch is going to follow the same pattern as the<br />
previous two. First I&#8217;m going to create the RSL and then add the RSL into the<br />
configuration.</p>
<h3>Create an RSL</h3>
<p class="MsoNormal">As usual I compile the monkey patched files into a library<br />
and create a link report. The link report becomes the basis of my externs file.<br />
The size of the monkey patch RSL without externalizing any classes is 38,260<br />
bytes.</p>
<p class="MsoNormal">Next I start removing classes from the externs file. First I<br />
remove ListCollectionView itself. ListCollectionView extends flash.utils.Proxy.<br />
Proxy is already externalized in playerglobal.swc so nothing to do. Next remove<br />
the three classes ListCollectionView implements, ICollectionView, IList, and<br />
IMXMLObject. ICollectionView and IList both implement IEventDispatcher.<br />
IEventDispatcher is also in playerglobals.swc so nothing to do. With all these<br />
classes removed from the externs file, recompile the RSL. </p>
<h3>Add the RSL to the configuration</h3>
<p class="MsoNormal">Since we are monkey patching the framework RSL, add the<br />
monkey patch RSL to load before the framework RSL. </p>
<p class="MsoNormal">At this point I thought I was done and ran the application.<br />
But I got a VerifyError on mx.collections.CursorBookmark. I couldn&#8217;t see how<br />
ListCollectionView extended or implemented CursorBookmark so I opened the catalog<br />
in framework.swc to double check. Sure enough CursorBookmark was an inheritance<br />
dependency of ListCollectionView. Inheritance dependencies are in the catalog<br />
as type=&#8221;i&#8221;.</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal" style="margin-top: 0in"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;dep<br />
id=&#8221;mx.collections:CursorBookmark&#8221; type=&#8221;i&#8221; /&gt; </span></p>
<p class="MsoNormal">I didn&#8217;t understand why so I searched ListCollectionView for<br />
CursorBookmark. I found a private class that extends CursorBookmark:</p>
<p class="MsoNormal"><span>class ListCollectionViewBookmark extends<br />
CursorBookmark</span></p>
<p class="MsoNormal">and another private class that implements IViewCursor:</p>
<p class="MsoNormal">class ListCollectionViewCursor extends EventDispatcher<br />
implements IViewCursor</p>
<p class="MsoNormal">With the mystery solved I removed CursorBookmark and<br />
IViewCursor from the externs file and recompiled. This time the application loaded<br />
without error although the application does not actually use ListCollectionView.<br />
The final size of the monkey patch RSL was 8,047 bytes.</p>
<p class="MsoNormal"><a href="http://blogs.adobe.com/dloverin/monkeyPatch/ListCollectionView.zip">Download Source</a></p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/dloverin/2010/02/monkey_patching_listcollectionview.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monkey Patching the Spark Button</title>
		<link>http://blogs.adobe.com/dloverin/2010/01/monkey_patching_the_spark_button.html</link>
		<comments>http://blogs.adobe.com/dloverin/2010/01/monkey_patching_the_spark_button.html#comments</comments>
		<pubDate>Sun, 31 Jan 2010 11:22:51 +0000</pubDate>
		<dc:creator>dloverin</dc:creator>
				<category><![CDATA[RSLs]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/dloverin/2010/01/monkey_patching_the_spark_button.html</guid>
		<description><![CDATA[This time around I&#8217;m going to monkey patch the Spark Button. Like last time I&#8217;ll patch the label property setter. The label property setter for the Spark Button is in spark.components.supportClasses.ButtonBase, not in spark.components.Button as you might expect. I&#8217;m going &#8230; <a href="http://blogs.adobe.com/dloverin/2010/01/monkey_patching_the_spark_button.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p class="MsoNormal">This time around I&#8217;m going to monkey patch the Spark Button.<br />
Like last time I&#8217;ll patch the label property setter. The label property setter<br />
for the Spark Button is in spark.components.supportClasses.ButtonBase, not in<br />
spark.components.Button as you might expect. I&#8217;m going to create an RSL<br />
containing the ButtonBase class and its inheritance dependencies and then slide<br />
that RSL into the RSL configuration.</p>
<h3>Create an RSL</h3>
<p class="MsoNormal">The ButtonBase class is compiled into spark.swc. I want to externalize<br />
as many classes as possible in my custom RSL so I&#8217;ll externalize all the<br />
libraries that spark.swc externalizes. That means I can externalize osmf.swc,<br />
textLayout.swc, and framework.swc. My application is not using any classes from<br />
osmf.swc so I won&#8217;t externalize that library and I won&#8217;t load that RSL either. </p>
<p class="MsoNormal">How do you know what libraries spark.swc is dependent on?<br />
One way is to look at the build file for spark.swc and see what libraries are<br />
on the external-library-path. Another way is to use the swcdepends tool. This<br />
tool is helpful in looking at dependencies between swcs and finding out what<br />
classes are causing those dependencies. I usually run it from the command line<br />
like this:</p>
<p class="MsoNormal"><span>&gt;swcdepends<br />
-locale=</span></p>
<p class="MsoNormal">The locale is set empty so that resource bundles are removed<br />
from the output. The swcdepends tool behaves like mxmlc in that it<br />
uses flex-config.xml and accepts the same configuration options. The output is<br />
a list of all the swcs found in dependency order. The swc with the least<br />
dependencies are at the top and the most dependencies are at the bottom. For<br />
each swc in the list, there is an indented list to show the actually swcs it is<br />
dependent on. Here an excerpt from the output showing the entry for spark.swc:</p>
<p class="MsoNormal"><span>C:\opensource\sdk\branches\4.0.0\frameworks\libs\spark.swc:</span></p>
<p class="MsoNormal"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>C:\opensource\sdk\branches\4.0.0\frameworks\libs\player\10.0\playerglobal.swc</span></p>
<p class="MsoNormal"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>C:\opensource\sdk\branches\4.0.0\frameworks\libs\osmf.swc</span></p>
<p class="MsoNormal"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>C:\opensource\sdk\branches\4.0.0\frameworks\libs\textLayout.swc</span></p>
<p class="MsoNormal"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>C:\opensource\sdk\branches\4.0.0\frameworks\libs\framework.swc</span></p>
<p class="MsoNormal">This shows that spark.swc is dependent on playerglobal.swc,<br />
osmf.swc, textLayout.swc, and framework.swc. If you want to show what classes<br />
are causing spark.swc to be dependent on the other libraries add the<br />
-show-external-classes to the command line.</p>
<p class="MsoNormal">Creating the custom library for ButtonBase was pretty easy.<br />
First I compiled with a list report and no externs file. The size of the RSL<br />
was 10,801 bytes. This was already much smaller than the mx Button RSL and I<br />
hadn&#8217;t even created an externs file yet. I copied the list report to the<br />
externs file and added a &#8220;load-externs=externs.xml&#8221; to the compc ant task. Next<br />
I edited the externs.xml file with the intent of removing ButtonBase and its<br />
inheritance dependencies. I removed ButtonBase and the SkinnableComponent class<br />
that ButtonBase extends. SkinnableComponent extends UIComponent but UIComponent<br />
is in framework.swc and was already externalized. ButtonBase implements<br />
IFocusManagerComponent which is also in framework.swc and does not need to be<br />
excluded. So were done after removing just two classes. </p>
<p class="MsoNormal">Compile again and check the link report. The link report<br />
shows just ButtonBase, SkinnableComponent and the root class so we are done.<br />
The custom RSL&#8217;s final size is 6,198 bytes.</p>
<h3>Add your RSL to the configuration<span style="font-size: 10pt;font-family: Mangal" lang="EN-CA"></span></h3>
<p class="MsoNormal">The custom RSL entry needs to be loaded after the framework<br />
RSL and before the spark RSL. The framework RSL will provide UIComponent and<br />
other classes we excluded. The custom RSL must be loaded before the spark RSL<br />
so the monkey patched class will override the spark class.</p>
<p class="MsoNormal">Running the application shows that the monkey patched<br />
version of ButtonBase is being used.</p>
<p class="MsoNormal"><a href="http://blogs.adobe.com/dloverin/monkeyPatch/sparkButton.zip">Download Source</a></p>
<p>
<p class="MsoNormal">&nbsp;</p>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/dloverin/2010/01/monkey_patching_the_spark_button.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Monkey Patch when using Flex RSLs</title>
		<link>http://blogs.adobe.com/dloverin/2010/01/how_to_monkey_patch_when_using_flex_rsls.html</link>
		<comments>http://blogs.adobe.com/dloverin/2010/01/how_to_monkey_patch_when_using_flex_rsls.html#comments</comments>
		<pubDate>Fri, 22 Jan 2010 17:44:35 +0000</pubDate>
		<dc:creator>dloverin</dc:creator>
				<category><![CDATA[RSLs]]></category>
		<category><![CDATA[monkey patch]]></category>

		<guid isPermaLink="false">http://blogs.adobe.com/dloverin/2010/01/how_to_monkey_patch_when_using_flex_rsls.html</guid>
		<description><![CDATA[Monkey patchers run into problems when using Flex RSLs. In this post I&#8217;ll explain why monkey patching does not work when using RSLs and provide details of how to make it work. I&#8217;ll monkey patch the mx.controls.Button class in this &#8230; <a href="http://blogs.adobe.com/dloverin/2010/01/how_to_monkey_patch_when_using_flex_rsls.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Monkey patchers run into problems when using Flex RSLs. In this post I&#8217;ll explain why monkey patching does not work when using RSLs and provide details of how to make it work.<span> </span>I&#8217;ll monkey patch the mx.controls.Button class in this post and ListCollectionView and Spark Button in later posts.<span> </span></p>
<p class="MsoNormal">Why doesn&#8217;t monkey patching work when using RSLs?<span> </span>To answer this question it is important to understand two things:</p>
<ol>
<li>
<div class="MsoListParagraphCxSpFirst">The Flash Player has a first-in-wins rule when loading classes.<span> </span></div>
</li>
<li>
<div class="MsoListParagraphCxSpLast">Flex applications contain two frames. The first frame contains few classes and loads the RSLs. The second frame contains the rest of the application&#8217;s classes.</div>
</li>
</ol>
<p class="MsoNormal">Say you&#8217;ve monkey patched mx.controls.Button, which will end up in frame 2 of your application. In frame 1 of the application, the framework RSL will be loaded which contains the mx.controls.Button class. When frame 2 of the application loads the monkey patched version of mx.controls.Button is ignored because of the Flash Player first-in-wins rule.</p>
<p class="MsoNormal">When you monkey patch a class that is in frame 1, then you are done, you don&#8217;t need an RSL.</p>
<p class="MsoNormal">The basic steps I&#8217;ll use to monkey patch are:</p>
<ol>
<li>
<div class="MsoListParagraphCxSpFirst">Create an RSL with just the monkey-patched file and its inheritance dependencies.</div>
</li>
<li>
<div class="MsoListParagraphCxSpLast">Add your RSL to the configuration to get it loaded.</div>
</li>
</ol>
<p class="MsoNormal">To demonstrate the process I created a <a href="http://blogs.adobe.com/dloverin/monkeyPatch/mxButton.zip">project</a> with a simple application that contains one button.</p>
<p class="MsoNormal">&lt;mx:Button label=&#8221;My Button&#8221;/&gt;</p>
<p class="MsoNormal">The project was developed using a pre-release version of Flex4, build 4.0.0.13672.</p>
<p>&nbsp;</p>
<h3>Create an RSL</h3>
<p class="MsoNormal">My modification of Button is just a change to set label() so I can see if a Button in my application is a real or patched Button. When the Button&#8217;s label setter is called I just prepend &#8220;Monkey patched &#8221; to the original value.</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal"><span><span> </span>_label = &#8220;Monkey patched &#8221; + value;</span></p>
<p class="MsoNormal">I started by adding Button.as to my source tree using the same package as Flex, &#8220;mx.controls&#8221;. Next compile your source into an RSL. From the command line it will look something like this:</p>
<p class="MsoNormal"><span>&gt;compc -directory -output=button -link-report=link.rpt -include-classes=mx.controls.Button -source-path=.</span></p>
<p class="MsoNormal"><span>&gt;optimizer<span> </span>button/library.swf &#8211;output -button.swf </span></p>
<p class="MsoNormal"><span>&#8211;keep-as3-metadata=Bindable,Managed,ChangeEvent,NonCommittingChangeEvent,Transient,SkinPart</span></p>
<p class="MsoNormal"><span>&gt;digest button.swf -swc-path=button</span><span> </span></p>
<p class="MsoNormal">After running these commands the size of button.swf is 143,596 bytes. Looking at the link report, there are a lot of classes besides mx.controls.Button that we don&#8217;t need. Ideally, all we want in the RSL is mx.controls.Button. But the Flash Player requires classes that Button extends or implements to be defined when the Button class is loaded. Since we are loading this RSL before the framework RSL, we need to also include the classes Button extends and implements in framework.swc.<span> </span>For each additional class we include, we also need to include the classes it extends and implements.</p>
<p class="MsoNormal">Take the link report from the first compile of Button and copy it to a file we will use as our externs file. The externs file is what we will use to remove classes we don&#8217;t want in the RSL. I actually seeded my externs.xml file by copying and pasting the script children from framework.swc&#8217;s catalog.<span> </span>My thinking was that I wanted to exclude everything in framework.swc except Button and the classes it extends or implements.<span> </span>But now I can see that the externs file is much larger than it would have been if I had just started with the initial link report.</p>
<p class="MsoNormal">Next edit the externs file by removing the script elements for mx.controls.Button and all of its inheritance dependencies.<span> </span>After recompiling I was able to get the RSL size down to 35,152 bytes. That is still pretty big but it&#8217;s the best we can do because we need UIComponent and UICompoment is big. When monkey patching spark components we will be able to remove UIComponent and get a much smaller RSL.</p>
<h3>Add your RSL to the configuration<span lang="EN-CA"> </span></h3>
<p class="MsoNormal"><span lang="EN-CA">Now that you have your RSL, you just need to add it to the RSL configuration.<span> </span>I created a local configuration file, main-config.xml, with the RSLs I wanted. You can start by copying the &lt;runtime-shared-library-path&gt; elements from flex-config.xml to your local configuration file. Then add the entry for your RSL before the framework RSL.</span></p>
<p class="MsoNormal"><span lang="EN-CA"><span> </span><span> </span></span><span lang="EN-CA">&lt;!&#8211; monkey patch mx.controls.Button from Framework SWC &#8211;&gt;</span></p>
<p class="MsoNormal"><span lang="EN-CA"><span> </span>&lt;runtime-shared-library-path&gt;</span></p>
<p class="MsoNormal"><span lang="EN-CA"><span> </span>&lt;path-element&gt;button&lt;/path-element&gt;</span></p>
<p class="MsoNormal"><span lang="EN-CA"><span> </span>&lt;rsl-url&gt;button.swf&lt;/rsl-url&gt;</span></p>
<p class="MsoNormal"><span lang="EN-CA"><span> </span>&lt;policy-file-url&gt;&lt;/policy-file-url&gt;</span></p>
<p class="MsoNormal"><span lang="EN-CA"><span> </span>&lt;/runtime-shared-library-path&gt;</span></p>
<p class="MsoNormal"><span lang="EN-CA">The order of the runtime-shared-library-path options is important because it determines the load order of the RSLs. The RSL URLs in my configuration file are all local SWF files so before running the application I will copy the RSLs from my SDK frameworks/RSLs directory to where my application lives. </span></p>
<p class="MsoNormal"><span lang="EN-CA">When the new RSL is loaded for the first time you will mostly encounter verify errors because you missed removing an interface from the externs file. As you encounter a verify error, remove that class from the externs file and try again. Eventually the RSL will contain all the classes it needs and load without errors.</span></p>
<p class="MsoNormal"><span lang="EN-CA">Finally, run the application to verify the monkey patched Button is being used.</span></p>
<p class="MsoNormal"><span><span lang="EN-CA"><span>The postings on this site are my own and don&#8217;t necessarily represent Adobe&#8217;s positions, views, strategies or opinions.</span></span></span></p>
<p class="MsoNormal"><span><span lang="EN-CA"> </span></span></p>
<p class="MsoNormal"><span lang="EN-CA"> </span></p>
<p class="MsoNormal"><span lang="EN-CA"> </span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.adobe.com/dloverin/2010/01/how_to_monkey_patch_when_using_flex_rsls.html/feed</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>
