<?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; ActionScript</title>
	<atom:link href="http://gauravj.com/blog/tag/actionscript/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>Troubleshooting ActionScript Code Coverage</title>
		<link>http://gauravj.com/blog/2011/02/troubleshooting-actionscript-code-coverage/</link>
		<comments>http://gauravj.com/blog/2011/02/troubleshooting-actionscript-code-coverage/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 23:12:07 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[Flex Tools]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Code Coverage]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://gauravj.com/blog/?p=896</guid>
		<description><![CDATA[<p>Sometimes folks run into situation with ActionScript code coverage plugin-in where the SWF files doesn&#8217;t make a connection. When this happens the plug-in stays in the &#8220;Listening..&#8221; status after the SWF is launched in Flash Player or AIR. Usually this happens because one the prerequisites for the tool is not being fulfilled. Before we <span style="color:#777"> . . . &#8594; Read More: <a href="http://gauravj.com/blog/2011/02/troubleshooting-actionscript-code-coverage/">Troubleshooting ActionScript Code Coverage</a></span>]]></description>
			<content:encoded><![CDATA[<p>Sometimes folks run into situation with ActionScript code coverage plugin-in where the SWF files doesn&#8217;t make a connection. When this happens the plug-in stays in the &#8220;Listening..&#8221; status after the SWF is launched in Flash Player or AIR. Usually this happens because one the prerequisites for the tool is not being fulfilled. Before we jump into the diagnosis, lets recap the prerequisites (which are listed in the <a href="http://labs.adobe.com/wiki/index.php/ActionScript_Code_Coverage:Using">docs</a>). </p>
<p><strong>Prerequisites:</strong></p>
<ul>
<li>Debug version of Flash Player</li>
<li>SWF file that has been compiled in debug mode </li>
<li>The preloaded SWF must be local trusted.</li>
</ul>
<p>Following is how you can ensure that the prerequisites are being met and possible resolutions:</p>
<p><strong>I.</strong> To ensure that you are using the debug version of flash player, you can simply compile and run the following mxml code and it should list the version and also if it supports debugging or not:</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:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #ff0000;">&quot;horizontal&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;application1_creationCompleteHandler(event)&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">		&lt;![CDATA[</span>
<span style="color: #339933;">			import mx.events.FlexEvent;</span>
<span style="color: #339933;">			protected function application1_creationCompleteHandler(event:FlexEvent):void</span>
<span style="color: #339933;">			{</span>
<span style="color: #339933;">				playerVersion.text = Capabilities.version;</span>
<span style="color: #339933;">				isDebugger.text = String(Capabilities.isDebugger);</span>
<span style="color: #339933;">			}</span>
<span style="color: #339933;">		]]&gt;</span>
<span style="color: #339933;">	&lt;/mx:Script&gt;</span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;Version&quot;</span><span style="color: #7400FF;">/&gt;</span><span style="color: #7400FF;">&lt;mx:Label</span> id=<span style="color: #ff0000;">&quot;playerVersion&quot;</span><span style="color: #7400FF;">/&gt;</span><span style="color: #7400FF;">&lt;mx:Label</span> text=<span style="color: #ff0000;">&quot;Supports Debugging? &quot;</span><span style="color: #7400FF;">/&gt;</span><span style="color: #7400FF;">&lt;mx:Label</span> id=<span style="color: #ff0000;">&quot;isDebugger&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

</blockquote>
<p><strong>Resolution:</strong> Reinstall debug version of flash player.</p>
<p><strong>II.</strong> To ensure that you are using the debug version of the SWF, you can run swfdump on the swf file. The swfdump generates an XML report. Look for tags like <strong>EnableDebugger2</strong> and <strong>DebugID</strong> in the report. If these tags are missing then you are probably running a release mode swf.</p>
<p><strong>Resolution:</strong> Recompile SWF with debug info. To do this from command line add -debug=true to mxmlc command. To do this from Flash builder, make sure debug is not set to false in additional compiler arguments or a local config file. </p>
<p><strong>III.</strong> To ensure that PreloadSwf is local trusted, you can follow the following steps:</p>
<ol>
<li>Run tail -f command on the mm.cfg file and then click the start button in code coverage plug-in.<br />
The mm.cfg file is present at the following location:</p>
<p><strong>XP:</strong> C:\Documents and Settings\<em>username</em><br />
<strong>Vista/Win7:</strong> C:\Users\<em>username</em><br />
<strong>Mac:</strong> /home/<em>username</em>  or if that doesn&#8217;t exist: /Library/Application Support/Macromedia</p>
<p>After you click the start button, the plugin should add a PreloadSwf entry to the mm.cfg file. <em>If it doesn&#8217;t then you should <strong>make sure that mm.cfg is writable and that the user has permissions</strong>.</em></p>
<p>An example of PreloadSwf entry:<br />
PreloadSwf=/Users/<em>username</em>/Documents/Adobe Flash Builder 4/.metadata/.plugins/com.adobe.flash.codecoverage/CodeCoverageAgent.swf?host=localhost&#038;port=9900&#038;level=0</p>
<p>Note down the absolute path of folder containing CodeCoverageAgent.swf. It should be in your FB workspace at <em>&lt;workspace&gt;/.metadata/.plugins/com.adobe.flash.codecoverage</em></p>
<p>Also the plug-in removes the PreloadSwf entry when you click the stop button</li>
<li>Inspect at the trust files.<br />
Location of trust file (per-user):<br />
<strong>XP</strong> C:\Documents and Settings\<em>username</em>\Application Data\Macromedia\Flash Player\#Security\FlashPlayerTrust<br />
<strong>Vista/Win7</strong>: C:\Users\<em>username</em>\AppData\Roaming\Macromedia\Flash Player\#Security\FlashPlayerTrust<br />
<strong>Mac:</strong> /Users/<em>username</em>/Library/Preferences/Macromedia/Flash Player/#Security/FlashPlayerTrust</p>
<p>Location of trust file (global):<br />
<strong>XP/Vista/Win7</strong> C:\WINDOWS\system32\Macromed\Flash\FlashPlayerTrust<br />
<strong>Mac</strong> /Library/Application Support/Macromedia/FlashPlayerTrust</p>
<p>The trust file is usually called flashbuilder.cfg. Make sure that the path of folder containing CodeCoverageAgent.swf is present in the trust file.
</li>
</ol>
<p><strong>Resolution:</strong> Add parent folder of CodeCoverageAgent.swf to the trust file. If the trust file is not present create a new trust file. Also it is important to restart your browser/AIR after changes to the trust file.</p>
<p>If all the prerequisites are being satisfied then make sure that the port number (9900) is free for use by code coverage plug-in. In case 9900 is not available then you should update the port number in the code coverage preferences.</p>
]]></content:encoded>
			<wfw:commentRss>http://gauravj.com/blog/2011/02/troubleshooting-actionscript-code-coverage/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Code Coverage Tool for ActionScript</title>
		<link>http://gauravj.com/blog/2010/09/code-coverage-tool-for-actionscript/</link>
		<comments>http://gauravj.com/blog/2010/09/code-coverage-tool-for-actionscript/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 02:45:28 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[Flex Tools]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Code Coverage]]></category>

		<guid isPermaLink="false">http://gauravj.com/blog/?p=800</guid>
		<description><![CDATA[<p>The prerelease for ActionScript Code Coverage Plug-in is now live on labs.adobe.com. On the Flex SDK team we use this tool to perform code coverage for the Flex Framework. This tool is not tied to any specific SDK version and so it can be used to perform code coverage using the latest SDK build. <span style="color:#777"> . . . &#8594; Read More: <a href="http://gauravj.com/blog/2010/09/code-coverage-tool-for-actionscript/">Code Coverage Tool for ActionScript</a></span>]]></description>
			<content:encoded><![CDATA[<p>The prerelease for <a href="http://labs.adobe.com/technologies/ascode_coverage/">ActionScript Code Coverage Plug-in</a> is now live on <a href="http://labs.adobe.com/">labs.adobe.com</a>. On the Flex SDK team we use this tool to perform code coverage for the Flex Framework. This tool is not tied to any specific SDK version and so it can be used to perform code coverage using the latest SDK build. Also any SWF compiled with -debug flag can be used to generate code coverage data. You can use it for your Flex Apps or AIR apps or pure AS3 apps. </p>
<p>For documentation related to the tool you can go <a href="http://labs.adobe.com/wiki/index.php/ActionScript_Code_Coverage:Using">here</a></p>
<p>This tool allows for the following:</p>
<ul>
<li>Choose between line and/or method level coverage</li>
<li>Apply filters on the view &#8211; so you can hide packages in which you are not interested</li>
<li>Save detailed reports &#8211; so you can view them later and compare with other coverage reports for your code base</li>
<li>Export high level coverage summary &#8211; This is a csv based summary of coverage for your code base</li>
</ul>
<p>When you save a detailed report, it creates two files on your system .ascc and .ascs. The .ascs file is a compressed file that contains the sources on which the coverage was performed. So if you want another engineers on your team to look at the coverage data, just give them the two files and they won&#8217;t need to sync to the sources on their computer (because the sources for the report will come from .ascs file).</p>
<p>It can even be used to perform code coverage for more than one applications at the same time (may be you have a library or framework for which you have a ton of test cases).</p>
<p>I encourage you to try the tool, and if you have any questions or feedback please use the <a href="http://forums.adobe.com/community/labs/ascode_coverage/">forum</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gauravj.com/blog/2010/09/code-coverage-tool-for-actionscript/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Creating SWC files with asdoc comments..</title>
		<link>http://gauravj.com/blog/2010/01/creating-swc-files-with-asdoc-comments/</link>
		<comments>http://gauravj.com/blog/2010/01/creating-swc-files-with-asdoc-comments/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 06:36:28 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[Flex Tools]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[ASDoc]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[SWC]]></category>

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

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

</blockquote>
<p>So give it a try, and if you find any bugs you can log them at <a href="http://bugs.adobe.com/flex">http://bugs.adobe.com/flex</a></p>
]]></content:encoded>
			<wfw:commentRss>http://gauravj.com/blog/2010/01/creating-swc-files-with-asdoc-comments/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Creating smaller swfs (Part II)</title>
		<link>http://gauravj.com/blog/2009/06/creating-smaller-swfs-part-ii/</link>
		<comments>http://gauravj.com/blog/2009/06/creating-smaller-swfs-part-ii/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 04:00:51 +0000</pubDate>
		<dc:creator>Gaurav</dc:creator>
				<category><![CDATA[Flex Framework]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[RSL]]></category>

		<guid isPermaLink="false">http://gauravj.com/blog/?p=149</guid>
		<description><![CDATA[<p>Here is the &#8220;Part II&#8221; of creating smaller swfs. In case you haven&#8217;t checked out the &#8220;Part I&#8221;, it can be found here: Creating smaller swfs (Part I). In this post, let&#8217;s focus on modules and how they can help in reducing the swf size.</p> What are Modules? <p>Modules are Flex swf files that <span style="color:#777"> . . . &#8594; Read More: <a href="http://gauravj.com/blog/2009/06/creating-smaller-swfs-part-ii/">Creating smaller swfs (Part II)</a></span>]]></description>
			<content:encoded><![CDATA[<p>Here is the &#8220;Part II&#8221; of creating smaller swfs. In case you haven&#8217;t checked out the &#8220;Part I&#8221;, it can be found here: <font color="#AAAAFF"><strong><em><a href="http://gauravj.com/blog/?p=20">Creating smaller swfs (Part I)</a></em></strong></font>.  In this post, let&#8217;s focus on modules and how they can help in reducing the swf size.</p>
<h2>What are Modules?</h2>
<p>Modules are Flex swf files that can be <em>dynamically</em> loaded by other swf files. So they allow you to break your large application into smaller pieces and gives you the flexibility to load the the required piece when/if required. In case you are wondering &#8220;How is Module different than RSL (since RSL can also be a swf and can be loaded by your application)&#8221;, the difference is that RSLs can <em><strong>only</strong></em> be loaded in frame 1 (i.e before your application initializes) but Modules can be loaded and unloaded <em><strong>whenever you want</strong></em> (after your application initializes) through out the life cycle of your application. Also note that you can not run modules independently, they always need to be loaded by another application. Benefits of modules are much more than just helping you to make your swf smaller, some of the benefits are:</p>
<ul>
<li><em>Improve start up time</em> by reducing the swf size.</li>
<li><em>Improves development time</em> because modules allows for code separation and can be independently compiled. So you can break you app into different functional pieces and have different developers/teams work on the different pieces as Modules.</li>
<li><em>Improves build time</em> because you need not recompile your entire application if changes are made to an independent module.</li>
<li><em>Improves integration</em> where you can&#8217;t upgrade all your code to the most recent version of Flex.</li>
</ul>
<h2>How to write Modules?</h2>
<p>You can write a module either using ActionScript or MXML. If your module is going to use any part of the Flex framework code then you must write a module based on mx.modules.Module. In case your module is <strong><em>not</em></strong>  going to use any part of the Flex framework code then you can write a module based on mx.modules.ModuleBase but then you must write it using ActionScript.</p>
<p>Here is an example of a module written using MXML (DataGridModule.mxml):</p>
<blockquote><pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
		   width="400" height="300" creationComplete="module1_creationCompleteHandler(event)"&gt;
	&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.controls.Alert;
			import mx.rpc.events.FaultEvent;
			import mx.events.FlexEvent;

			protected function module1_creationCompleteHandler(event:FlexEvent):void
			{
				srv.send();
			}

			protected function srv_faultHandler(event:FaultEvent):void
			{
				Alert.show("Can not retrieve data");
			}
		]]&gt;
	&lt;/mx:Script&gt;

	&lt;mx:HTTPService id="srv" url="catalog.xml" fault="srv_faultHandler(event)" /&gt;

	&lt;mx:DataGrid dataProvider="{srv.lastResult.report.account}" width="100%" height="100%"&gt;
		&lt;mx:columns&gt;
			&lt;mx:DataGridColumn dataField="month" headerText="Month"/&gt;
			&lt;mx:DataGridColumn dataField="sales" headerText="Sales" textAlign="right"/&gt;
			&lt;mx:DataGridColumn dataField="expenses" headerText="Expenses" textAlign="right"/&gt;
		&lt;/mx:columns&gt;
	&lt;/mx:DataGrid&gt;
&lt;/mx:Module&gt;
</code></pre>
</blockquote>
<p>As you can see the only thing special about the above code is the wrapping &lt;mx:Module&gt; tag, otherwise it looks pretty similar to a custom component (You can simply replace &lt;mx:Module&gt;, with say &lt;mx:VBox&gt; or &lt;mx:HBox&gt; and use it as a custom component)</p>
<p>The following is an example of a Module using ActionScript (ActionModule.as) which extends mx.modules.ModuleBase:</p>
<blockquote><pre><code>package
{
	import mx.modules.ModuleBase;

	public class ActionModule extends ModuleBase
	{
		public function ActionModule()
		{
			super();
		}

		public function calculateAverageProfit(arr:Array): String
		{
			var profit:Number = 0;

			for(var counter:int = 0; counter < arr.length; counter++)
			{
				var obj:Object = arr[counter];
				profit += obj.sales - obj.expenses;
			}

			return new Number(profit/arr.length).toFixed(2);
		}
	}
}</code></pre>
</blockquote>
<p>Since the above module (ActionModule.as) is for calculation purpose only, it doesn't depend upon any framework code and hence can extend from mx.modules.ModuleBase instead of mx.modules.Module</p>
<h2>How to use Modules?</h2>
<p>So now you probably have some idea about writing the modules, once you write the Modules, there are two techniques to load them into your application. </p>
<ol>
<li>Use ModuleLoader</li>
<li>Use ModuleManager and IModuleInfo</li>
</ol>
<p>Following is an example of an app which loads Module(s) (using both the techniques):</p>
<blockquote><pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
creationComplete="srv.send();"&gt;
	&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.modules.IModuleInfo;
			import mx.modules.ModuleManager;
			import mx.events.ModuleEvent;
			import mx.collections.ArrayCollection;
			import mx.rpc.events.ResultEvent;
			import mx.controls.Alert;
			import mx.rpc.events.FaultEvent;
			import mx.events.FlexEvent;

			private var result:ArrayCollection;

			private var moduleInfo:IModuleInfo;

			private var obj:Object;

			protected function srv_faultHandler(event:FaultEvent):void
			{
				Alert.show("Can not retrieve data");
			}
			protected function modLoader_errorHandler(event:ModuleEvent):void
			{
				Alert.show("Error in loading the Module.");
			}

			protected function srv_resultHandler(event:ResultEvent):void
			{
				result = event.result.report.account;
				linechart.dataProvider = result;
			}

			protected function showDataGrid_clickHandler(event:MouseEvent):void
			{
				modLoader.url = "DataGridModule.swf";
			}

			protected function showProfit_clickHandler(event:MouseEvent):void
			{
				moduleInfo = ModuleManager.getModule("ActionModule.swf");
				moduleInfo.addEventListener(ModuleEvent.READY, readyHandler);
				moduleInfo.addEventListener(ModuleEvent.ERROR, modLoader_errorHandler);
				moduleInfo.load();
			}

			private function readyHandler(event:ModuleEvent):void
			{
				obj = moduleInfo.factory.create();
				profitLbl.text = "Average Profit: $" + obj.calculateAverageProfit(result.source)
                                                 + " (in millions)";
			}
		]]&gt;
	&lt;/mx:Script&gt;
	&lt;mx:HTTPService id="srv" url="catalog.xml" fault="srv_faultHandler(event)"
                         result="srv_resultHandler(event)"/&gt;

	&lt;mx:LineChart id="linechart" color="0x323232" height="50%" showDataTips="true" &gt;
		&lt;mx:horizontalAxis&gt;
			&lt;mx:CategoryAxis categoryField="month"/&gt;
		&lt;/mx:horizontalAxis&gt;
		&lt;mx:series&gt;
			&lt;mx:LineSeries yField="sales" form="curve" displayName="Sales"/&gt;
			&lt;mx:LineSeries yField="expenses" form="curve" displayName="Expenses"/&gt;
		&lt;/mx:series&gt;
	&lt;/mx:LineChart&gt;
	&lt;mx:Legend dataProvider="{linechart}" color="0x323232"/&gt;
	&lt;mx:Label id="profitLbl" /&gt;
	&lt;mx:Button id="showProfit" click="showProfit_clickHandler(event)"
                 label="Show Average Profit"/&gt;
	&lt;mx:Button id="showDataGrid" click="showDataGrid_clickHandler(event)"
                 label="Show Details"/&gt;

	&lt;mx:ModuleLoader id="modLoader" error="modLoader_errorHandler(event)" /&gt;
&lt;/mx:Application&gt;
</code></pre>
</blockquote>
<p>In the above example the DataGridModule.swf is loaded using &lt;mx:ModuleManager/&gt;, the load is invoked when the url property is set (modLoder.url ="DataGridModule.swf"), which fires the urlChange event. Also you can invoke the load operation using the loadModule() method of ModuleLoader.  You can unload a module using the unloadModule() method.</p>
<p>The ActionModule.swf is loaded using ModuleManager and IModuleInfo, ModuleManager is used to get a reference to the IModuleInfo for ActionModule.swf and the actual load is invoked using the load() method on IModuleInfo.   </p>
<p>Notice that both techniques allow you to add a error handler (see modLoader_errorHandler() which takes event of type ModuleEvent), a error handler can be helpful to debug issue with module loading. Also there are other event types that you can use to find info related to loading (ModuleEvent.PROGRESS, ModuleEvent.READY, ModuleEvent.SETUP)</p>
<p>Here is the running swf. When you press on the button to "Show Average Profit", it loads the ActionModule.swf (which calculates the average profit). When you press on "Show Details", it loads the data grid module which shows the data in a datagrid.</p>
<p><center><br />
<iframe src ="http://gauravj.com/blog/examples/Modules/Dashboard.html" width="500" height="700"></p>
<p>Your browser does not support iframes.</p>
<p></iframe><br />
</center></p>
<p>Now for the size benefits:</p>
<table border="1">
<tr>
<th>Configuration</th>
<th>Swf size</th>
<th>Comments</th>
</tr>
<tr>
<td>Without Modules and RSLs</td>
<td>484 KB</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>With Modules</td>
<td>415 KB</td>
<td>In this case the benefit is small because we moved only a small portion of code into the module. Reduction in swf size depends upon the amount of code you move into modules. Expect higher benefits for large applications.</td>
</tr>
<tr>
<td>With Modules and RSLs</td>
<td>159 KB</td>
<td>This app was compiled with Flex 4 beta build. With a more recent Flex 4 build there should be increased benefits for swf size reduction.</td>
</tr>
</table>
<h2>Optimizing Modules</h2>
<p>So far you have seen how to use modules and how they can help to reduce the swf size. But when you compile a module swf, lot of core classes of the Flex framework (which are dependencies of mx.modules.Module) also get stitched into the module swf file, this creates a situation where you duplicate the same classes into your application (once in the main app and then in each module which is loaded by the app). However there is a compiler option to avoid this situation. You can compile you main app with the <strong>-link-report</strong> option, it will give you the link-report (a report that has the information regarding the byte code linkage) for your application. Then you can compile your module(s) with the <strong>-load-externs</strong> option and you can point the load-externs to the generated link report from the compilation of the main app. Its like telling the compiler that you already have taken care of classes which are in the link report, so don't add those to the module swf file.</p>
<p>Here are the example command I used:</p>
<p># compile main app - this will generate the main app swf and a link report named myLinkReport.xml<br />
./mxmlc -link-report=myLinkReport.xml Dashboard.mxml</p>
<p># compile module<br />
./mxmlc -load-externs=myLinkReport.xml DataGridModule.mxml</p>
<p>Or you can also use Flex/Flash Builder to set up the module optimization. You can do this via the project properties. Here are the steps:</p>
<ol>
<li>Right Click on the project and go to properties</li>
<li>Choose Flex Modules</li>
<p><img src="http://www.gauravj.com/blog/examples/Modules/modulesDialog.jpg" /><br />
You can see the modules in this dialog and whether they are being optimized or not. You can add new modules using the "Add" button.</p>
<li>Edit setting using the edit button or double click on the module</li>
<p><img src="http://www.gauravj.com/blog/examples/Modules/editModule.jpg" /><br />
Using this dialog, you can choose whether to optimize(and for which application) or not
</ol>
<p>The <strong>only situation</strong> where you should <strong>not</strong> optimize your modules is when you want to use your modules in different applications. Because optimized modules can only be used with application for which they were optimized.</p>
<h2>Shared Code problem</h2>
<p>When modules are loaded, the classes that are contained in the module are added into the child domain of the current application domain. So classes that are part of the module are owned by the module and not be the application. This can create an issue when two modules are using the same classes. When the first module has loaded, its class definitions gets registered, and module loaded after wards finds itself in a situation where the class definition that it contains doesn't matches with what is already registered. This usually creates issue with the manager classes like HistoryManager, PopUpManager etc. The error usually is a "Type Coercion" error, for example:</p>
<blockquote><p><strong>Type Coercion failed:</strong> cannot convert mx.managers::PopUpManagerImpl@ to mx.managers.IPopUpManager</p></blockquote>
<p>The solution is to make these classes part of the main app (so the main app is the owner of these class definitions and both managers can share them). If you simply add the import and variable declaration to the script block of the main app, you can avoid the issue with the classes that cause shared code problem</p>
<blockquote><p><code>import  mx.managers.HistoryManager;<br />
private var managerObj: HistoryManager;</code></p></blockquote>
<p>Alternatively you can also refactor code into a shared module and load the shared module <strong>before</strong> loading any other module.</p>
<h2>Modules and RSLs</h2>
<p>Using both modules are RSLs can significantly reduce swf size and start-up time. But if your app is using RSL (say for framework.swc) then your module swf does not need to use framework.swc as RSL. In such cases the library that will be loaded as RSL by the main app should just be in the external-library-path of the module. </p>
<p>This way since the RSL will already be loaded by the main app and available for consumption, for the module, the module will further save on load time because it won't even try to load the RSL (btw since the RSL is already loaded by the main app, the module will get it quickly get it from the cache so the saving per module is small but can add up if you are using lots of modules)</p>
<p>There is a bug (see <a href="http://bugs.adobe.com/jira/browse/FB-15470">FB-15470</a>) related to this in Flex Builder 3. The fix for the bug will be available in Flash Builder 4</p>
<p>So if you are using FB 3, here is how you can do this manually:<br />
You should move the modules into a seperate Flex Builder project and not list the libraries as rsls (instead just as -external-library-path for the libraries). That way the modules won't try to reload the rsls (because they would have already been loaded by the main app (for the project containing the main app you can continue to have the libraries listed as rsls)) </p>
]]></content:encoded>
			<wfw:commentRss>http://gauravj.com/blog/2009/06/creating-smaller-swfs-part-ii/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

