<?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>The Morphic Group &#187; Flash Builder</title>
	<atom:link href="http://www.themorphicgroup.com/blog/category/technology/flash-builder-technology/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.themorphicgroup.com/blog</link>
	<description></description>
	<lastBuildDate>Mon, 22 Feb 2010 18:20:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Flex 4 Custom Preloader</title>
		<link>http://www.themorphicgroup.com/blog/2009/11/11/flex-4-custom-preloader/</link>
		<comments>http://www.themorphicgroup.com/blog/2009/11/11/flex-4-custom-preloader/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 18:10:07 +0000</pubDate>
		<dc:creator>Seth</dc:creator>
				<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[flex 4]]></category>
		<category><![CDATA[preloader]]></category>

		<guid isPermaLink="false">http://www.themorphicgroup.com/blog/?p=340</guid>
		<description><![CDATA[In this example were going to look at a way to create a custom preloader SWC in Flash Professional and use it inside of a Flex 4 application by extending the SparkDownloadProgressBar class. This preloader will display the progress percentage of loading and also a count of RSLs as they are being loaded, after loading [...]]]></description>
			<content:encoded><![CDATA[<p>
In this example were going to look at a way to create a custom preloader SWC in Flash Professional and use it inside of a Flex 4 application by extending the SparkDownloadProgressBar class.<br />
<br />
This preloader will display the progress percentage of loading and also a count of RSLs as they are being loaded, after loading is complete the progress of initialization will be displayed. Both of the progresses will be displayed by a graphical progress bar and in text.
</p>
<p>
	<a href="http://www.themorphicgroup.com/examples/Flex4PreloaderExample/Flex4PreloaderExample.html" target="_blank"><strong>View Demo Preloader App</strong> (right click for source view)</a>
</p>
<p>
	The preloader may fly by, so lets first take a look at how this progress bar looks as it is loading the Flex app:<br />
	<br/><br />
	<img src="http://www.themorphicgroup.com/blog/wp-content/uploads/2009/11/flex4_preloader01.png" width="331" height="171" alt="flex 4 preloader" />
</p>
<p>
	The next screenshot shows the progress as RSLs are being loaded:<br />
	<br/><br />
	<img src="http://www.themorphicgroup.com/blog/wp-content/uploads/2009/11/flex4_preloader02.png" width="331" height="171" alt="flex 4 preloader" />
</p>
<p>
	Finally the progress of initialization, with a second progress bar:<br />
	<br/><br />
	<img src="http://www.themorphicgroup.com/blog/wp-content/uploads/2009/11/flex4_preloader03.png" width="331" height="171" alt="flex 4 preloader" />
</p>
<h2>Creating the Preloader SWC in Flash Pro</h2>
<p>
	In Flash professional we create a custom preloader. In this example there are several layers which the design is created from.<br />
	The layer 'prog_bar' and 'initilize_bar" hold shapes that we will use to resize to show progress.<br />
	The 'loading text' layer contains some dynamic text that has Character Embedding for upper/lower/numbers.<br />
	The layers look like this:
</p>
<p><img src="http://www.themorphicgroup.com/blog/wp-content/uploads/2009/11/flex4_preloader_flash.png" width="218" height="159" alt="flex 4 preloader" /></p>
<p>
	The custom preloader FLA can be found in the example by viewing source.
</p>
<p>
	The FLA preloader is a movie clip and its properties are set for &quot;Export for ActioScript&quot; the &quot;Class&quot; property is set to &quot;PreloaderDisplay&quot; this allows us to have a PreloaderDisplay.swc created when this FLA is published.
</p>
<p><a href="http://www.themorphicgroup.com/blog/wp-content/uploads/2009/11/flex4_preloader_flash_prop_large.png"><img src="http://www.themorphicgroup.com/blog/wp-content/uploads/2009/11/flex4_preloader_flash_prop_small.png" width="230" height="148" alt="flex 4 preloader" border="none" /></a></p>
<p>
	In the first frame of the FLA &quot;actions&quot; layer we create the functions to set the two different progress bars:
</p>
<pre class="actionscript3" style="font-family:monospace;">&nbsp;
<span style="color: #009900;">//reset</span>
setMainProgress<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
setInitalizeProgress<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span>;
loading_txt.<span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;&quot;</span>;
&nbsp;
<span style="color: #009900;">//function for setting main prgress bar</span>
<span style="color: #339966; font-weight: bold;">function</span> setMainProgress<span style="color: #000000;">&#40;</span>percent<span style="color: #000000; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html&amp;filter=0&amp;num=100&amp;btnI=lucky"><span style="color: #004993;">Number</span></a><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	prog_bar.<span style="color: #004993;">width</span> = percent <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">275</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #009900;">//function for setting the initilize bar</span>
<span style="color: #339966; font-weight: bold;">function</span> setInitalizeProgress<span style="color: #000000;">&#40;</span>percent<span style="color: #000000; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html&amp;filter=0&amp;num=100&amp;btnI=lucky"><span style="color: #004993;">Number</span></a><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	initialize_bar.<span style="color: #004993;">width</span> = percent <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">275</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
<p>
	The final step is to &quot;Publish&quot; the FLA so that the SWC file is create, this SWC will be used in Flash Builder.
</p>
<h2>Creating the Custom Preloader in Flex 4</h2>
<p>
	The first step is to place the PreloaderDisplay.swc in the &quot;libs&quot; folder, this will make the PreloaderDisplay and its methods available to Flex:
</p>
<p><img src="http://www.themorphicgroup.com/blog/wp-content/uploads/2009/11/flex4_preloader_libs.png" width="189" height="55" alt="preloader swc libs" /></p>
<p>
	To define a custom preloader we will do this in the Flex application's Application file, we simply specify the preloader class:
</p>
<pre class="actionscript3" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>s<span style="color: #000000; font-weight: bold;">:</span>Application preloader=<span style="color: #990000;">&quot;com.themorphicgroup.preload.Preloader&quot;</span> ...
&nbsp;</pre>
<p>
	In the Preloader class we will extend &quot;SparkDownloadProgressBar&quot;.</p>
<p>	The SparkDownloadProgressBar class displays download progress. </p>
<p>	From Flex 4 docs: It is used by the Preloader control to provide user feedback while the application is downloading and loading.<br />
	The download progress bar displays information about two different phases of the application: the download phase and the initialization phase.
</p>
<p>
	The Preloader.as extends &quot;SparkDownloadProgressBar&quot; and we will use the FLA PreloaderDisplay.swc by creating a variable called &quot;preloaderDisplay&quot;:
</p>
<pre class="actionscript3" style="font-family:monospace;">&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Preloader extends SparkDownloadProgressBar <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> preloaderDisplay<span style="color: #000000; font-weight: bold;">:</span>PreloaderDisplay;
	...
&nbsp;</pre>
<p>
	To add the PreloaderDisplay we will override the SparkDownloadProgressBar's &quot;createChildren&quot; method, in this method we will create a new PreloaderDisplay and<br />
	use the &quot;addChild&quot; method (SparkDownloadProgressBar inherits addChild from DisplayObjectContainer):
</p>
<pre class="actionscript3" style="font-family:monospace;">&nbsp;
override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> createChildren<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span>preloaderDisplay<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		preloaderDisplay = <span style="color: #0033ff; font-weight: bold;">new</span> PreloaderDisplay<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
		<span style="color: #6699cc; font-weight: bold;">var</span> startX<span style="color: #000000; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html&amp;filter=0&amp;num=100&amp;btnI=lucky"><span style="color: #004993;">Number</span></a> = <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html&amp;filter=0&amp;num=100&amp;btnI=lucky"><span style="color: #004993;">Math</span></a>.<span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">stageWidth</span> <span style="color: #000000; font-weight: bold;">-</span> preloaderDisplay.<span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #6699cc; font-weight: bold;">var</span> startY<span style="color: #000000; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html&amp;filter=0&amp;num=100&amp;btnI=lucky"><span style="color: #004993;">Number</span></a> = <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html&amp;filter=0&amp;num=100&amp;btnI=lucky"><span style="color: #004993;">Math</span></a>.<span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">stageHeight</span> <span style="color: #000000; font-weight: bold;">-</span> preloaderDisplay.<span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#41;</span>;
&nbsp;
		preloaderDisplay.<span style="color: #004993;">x</span> = startX;
		preloaderDisplay.<span style="color: #004993;">y</span> = startY;
		<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>preloaderDisplay<span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
<p>
	There are several methods that we will override so that we can make updates to the PreloaderDisplay.swc.<br />
	The rslProgressHandler method will be called each time a RSL is being loaded. We will use this method to set text indicating the current count of RSL being loaded:
</p>
<pre class="actionscript3" style="font-family:monospace;">&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> rslBaseText<span style="color: #000000; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html&amp;filter=0&amp;num=100&amp;btnI=lucky"><span style="color: #004993;">String</span></a> = <span style="color: #990000;">&quot;loading: &quot;</span>;
override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> rslProgressHandler<span style="color: #000000;">&#40;</span>evt<span style="color: #000000; font-weight: bold;">:</span>RSLEvent<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>evt.rslIndex <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> evt.rslTotal<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #009900;">//create text to track the RSLs being loaded</span>
		rslBaseText = <span style="color: #990000;">&quot;loading RSL &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> evt.rslIndex <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; of &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> evt.rslTotal <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;: &quot;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
<p>
	The next method we will override is setDownloadProgress. This method indicateds the current download progress. in this method we will set the<br />
	PreloaderDisplay.swc main progress bar and set the text:
</p>
<pre class="actionscript3" style="font-family:monospace;">&nbsp;
override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> setDownloadProgress<span style="color: #000000;">&#40;</span>completed<span style="color: #000000; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html&amp;filter=0&amp;num=100&amp;btnI=lucky"><span style="color: #004993;">Number</span></a>, total<span style="color: #000000; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html&amp;filter=0&amp;num=100&amp;btnI=lucky"><span style="color: #004993;">Number</span></a><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>preloaderDisplay<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #009900;">//set the main progress bar inside PreloaderDisplay</span>
		preloaderDisplay.setMainProgress<span style="color: #000000;">&#40;</span>completed<span style="color: #000000; font-weight: bold;">/</span>total<span style="color: #000000;">&#41;</span>;
		<span style="color: #009900;">//set percetage text to display, if loading RSL the rslBaseText will indicate the number</span>
		setPreloaderLoadingText<span style="color: #000000;">&#40;</span>rslBaseText <span style="color: #000000; font-weight: bold;">+</span> <a href="http://www.google.com/search?q=math%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:math.html&amp;filter=0&amp;num=100&amp;btnI=lucky"><span style="color: #004993;">Math</span></a>.<span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>completed<span style="color: #000000; font-weight: bold;">/</span>total<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot;%&quot;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
<p>
	Finally we will look at overriding setInitProgress, this method indicates the progress of the Flex app as it initializes.<br />
	We will set the text in PreloaderDisplay.swc and change the progress of the second initialize progress bar:
</p>
<pre class="actionscript3" style="font-family:monospace;">&nbsp;
override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> setInitProgress<span style="color: #000000;">&#40;</span>completed<span style="color: #000000; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html&amp;filter=0&amp;num=100&amp;btnI=lucky"><span style="color: #004993;">Number</span></a>, total<span style="color: #000000; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html&amp;filter=0&amp;num=100&amp;btnI=lucky"><span style="color: #004993;">Number</span></a><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>preloaderDisplay<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #009900;">//set the initialization progress bar inside PreloaderDisplay</span>
		preloaderDisplay.setInitalizeProgress<span style="color: #000000;">&#40;</span>completed<span style="color: #000000; font-weight: bold;">/</span>total<span style="color: #000000;">&#41;</span>;
		<span style="color: #009900;">//set loading text</span>
		<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>completed <span style="color: #000000; font-weight: bold;">&gt;</span> total<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			setPreloaderLoadingText<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;almost done&quot;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
			setPreloaderLoadingText<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;initializing &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> completed <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #990000;">&quot; of &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> total<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;</pre>
<p>&nbsp;</p>
<p>
	This blog entry does not cover every bit of code used in the preloader, so<br />
	<a href="http://www.themorphicgroup.com/examples/Flex4PreloaderExample/Flex4PreloaderExample.html" target="_blank"><strong>View Demo Preloader App</strong> right click for source view</a>
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.themorphicgroup.com/blog/2009/11/11/flex-4-custom-preloader/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>“Content Assist” did not complete normally &#8211; bat file workaround</title>
		<link>http://www.themorphicgroup.com/blog/2009/11/03/%e2%80%9ccontent-assist%e2%80%9d-did-not-complete-normally-bat-file-workaround/</link>
		<comments>http://www.themorphicgroup.com/blog/2009/11/03/%e2%80%9ccontent-assist%e2%80%9d-did-not-complete-normally-bat-file-workaround/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 15:34:55 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Adobe Flash Builder 4]]></category>
		<category><![CDATA[com.adobe.flexbuilder.codemodel]]></category>
		<category><![CDATA[Content Assist]]></category>
		<category><![CDATA[Flash Builder 4 beta 2]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[FlexBuilder]]></category>
		<category><![CDATA[FlexBuiler]]></category>

		<guid isPermaLink="false">http://www.themorphicgroup.com/blog/?p=334</guid>
		<description><![CDATA[Follow up to my last post. I am having to do this enough that I wrote a bat file for it. Here is what it looks like if anyone is interested. Just copy and paste the code below into a notepad and save as a .bat file. I put mine in the root of my [...]]]></description>
			<content:encoded><![CDATA[<p>Follow up to my last post.  I am having to do this enough that I wrote a bat file for it.  Here is what it looks like if anyone is interested.  Just copy and paste the code below into a notepad and save as a .bat file.  I put mine in the root of my C: drive so I can simple do Start-->Run-->fix_content_assist.bat</p>
<p>fix_content_assist.bat<br />
<code><br />
@echo off<br />
REM The following will delete the prefs file in Flash Builder 4 Beta 2 that caused content assist to break<br />
RMDIR C:\work\dev\morphic\myproject\trunk\code\as_fb4\.metadata\.plugins\com.adobe.flexbuilder.codemodel /s /q<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.themorphicgroup.com/blog/2009/11/03/%e2%80%9ccontent-assist%e2%80%9d-did-not-complete-normally-bat-file-workaround/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
