<?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>Anselm Bradford &#187; Tutorial</title>
	<atom:link href="http://blog.anselmbradford.com/category/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.anselmbradford.com</link>
	<description>wrangling the Internet's wildest</description>
	<lastBuildDate>Mon, 27 Jun 2011 19:17:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How to add a webpage fade-in effect using JQuery</title>
		<link>http://blog.anselmbradford.com/2009/08/28/how-to-add-a-simple-webpage-fade-in-effect-using-jquery/</link>
		<comments>http://blog.anselmbradford.com/2009/08/28/how-to-add-a-simple-webpage-fade-in-effect-using-jquery/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 15:19:11 +0000</pubDate>
		<dc:creator>Ans</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.anselmbradford.com/?p=924</guid>
		<description><![CDATA[THE PROBLEM: HTML pages that have numerous and complex nested &#60;div&#62; tags and CSS can sometimes have a jumbled &#8220;assembling&#8221; appearance that happens as the page is loading and the various elements are being rendered by the browser. The appearance of this process can look quite unrefined and detract from professional appearance of the site. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>THE PROBLEM:</strong> HTML pages that have numerous and complex nested &lt;div&gt; tags and CSS can sometimes have a jumbled &#8220;assembling&#8221; appearance that happens as the page is loading and the various elements are being rendered by the browser. The appearance of this process can look quite unrefined and detract from professional appearance of the site.</p>
<p><strong>A SOLUTION:</strong> JQuery includes a function to <a href="http://docs.jquery.com/Effects/fadeIn" onclick="pageTracker._trackPageview('/outgoing/docs.jquery.com/Effects/fadeIn?referer=');">fade-in</a> a hidden tag. If the content of the page is initially hidden using CSS, it then can be faded-in using JQuery once the whole page has been processed and is ready for display. </p>
<h3>Step 1</h3>
<p>Inside the page&#8217;s &lt;body&gt; tag, enclose the content in a &lt;div&gt; tag with a unique CSS id (<a href="http://blog.anselmbradford.com/2008/12/20/the-difference-between-ids-and-classes-in-css/">see this post for the difference between CSS ids and classes</a>).</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;content-wrapper&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
The page content goes here!
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #808080; font-style: italic;">&lt;!-- content-wrapper --&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h3>Step 2</h3>
<p>Inside the page&#8217;s &lt;head&gt; tag, import the JQuery library (<a href="http://docs.jquery.com/Downloading_jQuery" onclick="pageTracker._trackPageview('/outgoing/docs.jquery.com/Downloading_jQuery?referer=');">download it here</a>) and create a fade-in effect on the &lt;div&gt; tag surrounding the page&#8217;s content. Key to this solution is that the effect gets placed inside JQuery&#8217;s <code>$(document).ready()</code> function, ensuring the fade begins after the document&#8217;s DOM has been completely parsed.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;jquery.min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
$(document).ready(function() 
{
		// fade in content.
		$( '#content-wrapper' ).fadeIn(&quot;slow&quot;);		
});
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h3>Step 3</h3>
<p>At this point the fade-in effect will not occur, because the content is not hidden to begin with. To correct this add some CSS styling underneath the JavaScript above to hide the page content initially.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
#content-wrapper
{
	display:none;	
}
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h3>Step 4</h3>
<p>Now the fade-in effect will work, however, a problem exists. If someone visits the page and has JavaScript turned off in their browser, the CSS to hide the content will be applied, but the JQuery to fade it back into visibility will not run, leaving the page effectively blank. This is a serious accessibility issue. To correct this, instead of hardcoding the &lt;div&gt; tag that is wrapping the content, write the tag using JavaScript. That way if JavaScript is turned off, the tag will not be rendered and won&#8217;t hide its containing content. Change what was written in Step 1 to the following:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!--//--&gt;</span><span style="color: #339933;">&lt;![CDATA[//&gt;&lt;!--</span>
<span style="color: #339933;">document.write( '&lt;div id=&quot;content-wrapper&quot;&gt;' );</span>
<span style="color: #339933;">//--&gt;&lt;!]]&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
The page content goes here!
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!--//--&gt;</span><span style="color: #339933;">&lt;![CDATA[//&gt;&lt;!--</span>
<span style="color: #339933;">document.write( '&lt;/div&gt;&lt;!-- content-wrapper --&gt;' );</span>
<span style="color: #339933;">//--&gt;&lt;!]]&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Putting it all together you end up with this (remember to include the JQuery library in the same folder as this HTML page):</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;meta</span> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Fade-in effect example<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;jquery.min.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
$(document).ready(function() 
{
		// fade in content.
		$( '#content-wrapper' ).fadeIn(&quot;slow&quot;);		
});
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;style</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
#content-wrapper
{
	display:none;	
}
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!--//--&gt;</span><span style="color: #339933;">&lt;![CDATA[//&gt;&lt;!--</span>
<span style="color: #339933;">document.write( '&lt;div id=&quot;content-wrapper&quot;&gt;' );</span>
<span style="color: #339933;">//--&gt;&lt;!]]&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
The page content goes here!
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!--//--&gt;</span><span style="color: #339933;">&lt;![CDATA[//&gt;&lt;!--</span>
<span style="color: #339933;">document.write( '&lt;/div&gt;&lt;!-- content-wrapper --&gt;' );</span>
<span style="color: #339933;">//--&gt;&lt;!]]&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.anselmbradford.com/2009/08/28/how-to-add-a-simple-webpage-fade-in-effect-using-jquery/feed/</wfw:commentRss>
		<slash:comments>50</slash:comments>
		</item>
		<item>
		<title>How to build an Object-Oriented ActionScript 3 Preloader in Flash CS4: 2 Methods</title>
		<link>http://blog.anselmbradford.com/2009/06/20/how-to-build-an-object-oriented-actionscript-3-preloader-in-flash-cs4-2-methods/</link>
		<comments>http://blog.anselmbradford.com/2009/06/20/how-to-build-an-object-oriented-actionscript-3-preloader-in-flash-cs4-2-methods/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 03:26:05 +0000</pubDate>
		<dc:creator>Ans</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.anselmbradford.com/?p=836</guid>
		<description><![CDATA[The magic of creating a preloader in ActionScript 3 lies in the LoaderInfo class. Every instantiated DisplayObject instance (all objects that appear on the stage, plus the stage itself) have a loaderInfo property that returns a LoaderInfo instance that contains information about the loading progress of that particular display object. Creating a preloader for the [...]]]></description>
			<content:encoded><![CDATA[<p>The magic of creating a preloader in ActionScript 3 lies in the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/LoaderInfo.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/LoaderInfo.html?referer=');">LoaderInfo</a> class. Every instantiated DisplayObject instance (all objects that appear on the stage, plus the stage itself) have a <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html#loaderInfo" onclick="pageTracker._trackPageview('/outgoing/livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html_loaderInfo?referer=');">loaderInfo</a> property that returns a LoaderInfo instance that contains information about the loading progress of that particular display object. Creating a preloader for the whole application is a matter of monitoring these LoaderInfo instances.</p>
<h3>Method 1: Monitor Stage LoaderInfo instance</h3>
<p>Under this method the loading progress is monitored via the LoaderInfo instance associated with the stage. Since all assets that will appear in the application need to be attached to the stage, the stage&#8217;s LoaderInfo instance will reflect the loading of all these assets.</p>
<h4>Graphics</h4>
<ol>
<li>Go to File &#8594; New&#8230; and select Flash File (ActionScript 3.0).</li>
<li>Using the Rectangle tool create a rectangle (include a stroke) on the stage that is 100 pixels wide by 10 pixels high.</li>
<li>Click on the fill of the newly created rectangle and select Modify &#8594; Convert to Symbol&#8230; Name the new instance <em>ProgBar</em> and set the registration point to left-middle. This will be the progress bar of the preloader.
<p><img class="border" src="http://blog.anselmbradford.com/wp-content/uploads/2009/06/preloader_pbar.png" alt="preloader_pbar" title="preloader_pbar" width="626" height="289" class="alignnone size-full wp-image-844" /></p>
</li>
<li>With the new ProgBar instance selected on the stage, go to the Properties panel and name the instance <em>progBar</em>.</li>
<li>Select the whole rectangle (stroke and progress bar instance). Select Modify &#8594; Convert to Symbol&#8230; Name the new instance <em>Preloader</em> and set the registration point to left-middle. Check the <em>Export for ActionScript</em> button.
<li>Click <em>OK</em>. If you get a warning that says the &#8220;definition for this class could not be found&#8221; click <em>OK</em> again.</li>
<li>With the new Preloader instance selected, go to the Properties panel and name the newly created instance <em>preloader</em>. Your library should look like the following:
<p><img class="border" src="http://blog.anselmbradford.com/wp-content/uploads/2009/06/preloader_library.png" alt="preloader_library" title="preloader_library" width="285" height="153" class="alignnone size-full wp-image-848" /></p>
</li>
<li>Select frame 2 of the main timeline, go to Insert &#8594; Timeline &#8594; Blank Keyframe. All content for the application will appear on frame 2 and beyond.</li>
<li>Go to Insert &#8594; New Symbol&#8230; Name the new instance <em>Content</em>. If you check <em>Export for ActionScript</em> be sure to <strong>uncheck <em>Export in frame 1</em></strong>, otherwise the preloader will not function properly.</li>
<li>Place all content of the application on the timeline of the newly created Content instance.</li>
<li>Return to the main timeline. Select frame 2 and drag an instance of the Content symbol from the library and place it on the stage.</li>
<li>In the Properties panel of the stage name the document class <em>Main</em>. If you get a warning that says the &#8220;definition for this class could not be found&#8221; click <em>OK</em>.
<p><img class="border" src="http://blog.anselmbradford.com/wp-content/uploads/2009/06/preloader_docclass.png" alt="preloader_docclass" title="preloader_docclass" width="283" height="200" class="alignnone size-full wp-image-854" /></p>
</li>
<li>Save the file.</li>
</ol>
<h4>Code</h4>
<ol>
<li>Go to File &#8594; New&#8230; and select ActionScript File.</li>
<li>Paste the following code and save the file as <em>Preloader.as</em> in the same directory as the .fla file saved earlier.

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">LoaderInfo</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Preloader <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">/**
		* Alias for stage LoaderInfo instance
		*/</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _targetLoaderInfo:LoaderInfo;
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		* The percent loaded
		*/</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _loadPercent:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		* Constructor
		* Listen for when the preloader has been added to the stage 
		* so that the progress of the remaining load can be monitored.
		*/</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Preloader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ADDED_TO_STAGE</span> , _init <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		* Initialize variables.
		* Set initial width of the progress bar to 0 
		* and listen for enter frame event.
		*/</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _init<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_targetLoaderInfo = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">loaderInfo</span>;
&nbsp;
			progBar.<span style="color: #006600;">scaleX</span> = <span style="color: #cc66cc;">0</span>;
&nbsp;
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ADDED_TO_STAGE</span> , _init <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, _onCheckLoaded<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		* Check the status of the load, once complete dispatch a complete event.
		*/</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _onCheckLoaded<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> 
		<span style="color: #66cc66;">&#123;</span>
			_loadPercent = _targetLoaderInfo.<span style="color: #0066CC;">bytesLoaded</span> <span style="color: #66cc66;">/</span> _targetLoaderInfo.<span style="color: #0066CC;">bytesTotal</span>;
			progBar.<span style="color: #006600;">scaleX</span> = _loadPercent;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>progBar.<span style="color: #006600;">scaleX</span> == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #0066CC;">this</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, _onCheckLoaded<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #0066CC;">this</span>.<span style="color: #006600;">dispatchEvent</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>	
<span style="color: #66cc66;">&#125;</span></pre></div></div>

</li>
<li>Go to File &#8594; New&#8230; and select ActionScript File a second time.</li>
<li>Paste the following code and save the file as <em>Main.as</em> in the same directory as the .fla file saved earlier.

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package 
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> 
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">/**
		* Constructor
		* Stop timeline and add event listener to preloader.
		*/</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> 
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			preloader.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">COMPLETE</span> , _initContent <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		* Load has finished, remove preloader and preceed to next frame.
		*/</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _initContent<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> 
		<span style="color: #66cc66;">&#123;</span>
			preloader.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">COMPLETE</span> , _initContent <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span>preloader<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">nextFrame</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

</li>
<li>To test the preloader go to Control &#8594; Test Movie. Go to View &#8594; Simulate Download.</li>
<li><a href='/wp-content/uploads/2009/06/preloader_method1.zip'>Download method 1 complete source</a></li>
</ol>
<h3>Method 2: Monitor content SWF LoaderInfo instance</h3>
<p>Under this method two SWFs are created, one encapsulating the preloader and the other encapsulating all content. The content SWF is loaded inside of the preloader SWF, which monitors the loading progress.</p>
<h4>Graphics</h4>
<ol>
<li>Follow steps 1 &#8211; 7 in the previous method.</li>
<li>In the Properties panel of the stage name the document class <em>PreloaderWrapper</em>. If you get a warning that says the &#8220;definition for this class could not be found&#8221; click <em>OK</em>.</li>
<li>Save the file.</li>
<li>Go to File &#8594; New&#8230; and select Flash File (ActionScript 3.0).</li>
<li>Add the content for your application to the timeline of this file.</li>
<li>Save the file as <em>content.fla</em>.</li>
<li>Go to Control &#8594; Test Movie to create the content.swf that will be loaded by the preloader SWF.</li>
</ol>
<h4>Code</h4>
<ol>
<li>Go to File &#8594; New&#8230; and select ActionScript File.</li>
<li>Paste the following code and save the file as <em>PreloaderWrapper.as</em> in the same directory as the .fla file saved earlier.

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package 
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Loader</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">LoaderInfo</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">DisplayObject</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">ProgressEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PreloaderWrapper <span style="color: #0066CC;">extends</span> Sprite 
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">/**
		* Alias for content LoaderInfo instance
		*/</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _targetLoaderInfo:LoaderInfo;
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		* The percent loaded
		*/</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _loadPercent:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		* Constructor
		* Creates Loader instance, adds event listeners and begins loading content SWF.
		*/</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> PreloaderWrapper<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> 
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_targetLoaderInfo = loader.<span style="color: #006600;">contentLoaderInfo</span>;
			_targetLoaderInfo.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> ProgressEvent.<span style="color: #006600;">PROGRESS</span>, _loadingData <span style="color: #66cc66;">&#41;</span>;
			_targetLoaderInfo.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">COMPLETE</span> , _finishedLoading <span style="color: #66cc66;">&#41;</span>;
			loader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;content.swf&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		* Monitor loading progress and update progress bar.
		*/</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _loadingData<span style="color: #66cc66;">&#40;</span> evt:ProgressEvent <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> 
		<span style="color: #66cc66;">&#123;</span>
			_loadPercent = _targetLoaderInfo.<span style="color: #0066CC;">bytesLoaded</span> <span style="color: #66cc66;">/</span> _targetLoaderInfo.<span style="color: #0066CC;">bytesTotal</span>;
			preloader.<span style="color: #006600;">progBar</span>.<span style="color: #006600;">scaleX</span> = _loadPercent;	
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		* Remove event listeners and preloader, and attach content SWF to stage.
		*/</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _finishedLoading<span style="color: #66cc66;">&#40;</span> evt:Event <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> 
		<span style="color: #66cc66;">&#123;</span>
			_targetLoaderInfo.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span> ProgressEvent.<span style="color: #006600;">PROGRESS</span>, _loadingData <span style="color: #66cc66;">&#41;</span>;
			_targetLoaderInfo.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">COMPLETE</span> , _finishedLoading <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">removeChild</span><span style="color: #66cc66;">&#40;</span>preloader<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span> DisplayObject<span style="color: #66cc66;">&#40;</span>LoaderInfo<span style="color: #66cc66;">&#40;</span>evt.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

</li>
<li>To test the preloader go to Control &#8594; Test Movie. Go to View &#8594; Simulate Download.</li>
<li><a href='/wp-content/uploads/2009/06/preloader_method2.zip'>Download method 2 complete source</a></li>
</ol>
<p><strong>UPDATE July 30, 2009:</strong> I noticed I forgot the <em>private</em> designation on two of the methods in the PreloaderWrapper class. They have been added.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anselmbradford.com/2009/06/20/how-to-build-an-object-oriented-actionscript-3-preloader-in-flash-cs4-2-methods/feed/</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
		<item>
		<title>Curious about Adobe Open Source? Get started with the Flex SDK on Mac OS X</title>
		<link>http://blog.anselmbradford.com/2009/01/06/curious-about-adobe-open-source-get-started-with-the-flex-sdk-on-mac-os-x/</link>
		<comments>http://blog.anselmbradford.com/2009/01/06/curious-about-adobe-open-source-get-started-with-the-flex-sdk-on-mac-os-x/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 13:12:50 +0000</pubDate>
		<dc:creator>Ans</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.anselmbradford.com/?p=548</guid>
		<description><![CDATA[How about creating a SWF that runs in the Adobe Flash Player without building it in the Flash or Flex Builder authoring environment, using tools that are free and open source? Ever since Adobe made the move from ActionScript 2.0 to 3.0 there has been a gem of a toolkit available that allows precisely that. [...]]]></description>
			<content:encoded><![CDATA[<p>How about creating a SWF that runs in the Adobe Flash Player without building it in the Flash or Flex Builder authoring environment, using tools that are free and open source? Ever since Adobe made the move from ActionScript 2.0 to 3.0 there has been a gem of a toolkit available that allows precisely that. The Flex SDK (Software Development Kit) allows developers to create SWFs from ActionScript and MXML source code, and with the right setup is not difficult to configure and use. </p>
<p>Housed at <a href="http://opensource.adobe.com" onclick="pageTracker._trackPageview('/outgoing/opensource.adobe.com?referer=');">Adobe Open Source</a>, the Flex SDK is available in two incarnations through the site: </p>
<ul>
<li><strong>The Open Source Flex SDK</strong> containing everything needed to create a functional application using ActionScript and/or MXML and the Flex framework. </li>
<li><strong>The Free Adobe Flex 3 SDK</strong> containing everything in the Open Source Flex SDK plus additional components such as advanced font encoders, tools for packaging Adobe AIR applications, and the Adobe Flash Player.
</li>
<h4>How to use the Flex SDK</h4>
<p>I have developed an Apache Ant build script that makes—after some configuration—the Flex SDK quite easy to use on Mac OS X. Here&#8217;s how to configure it:</p>
<ol>
<li><a href="http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK" onclick="pageTracker._trackPageview('/outgoing/opensource.adobe.com/wiki/display/flexsdk/Flex+SDK?referer=');">Download the latest Flex SDK</a> from Adobe Open Source. Rename the SDK folder <code>flex_sdk_3</code> and place it in <code>/Applications/</code> on your hard drive.</li>
<li>Locate <a href="http://ant.apache.org/" onclick="pageTracker._trackPageview('/outgoing/ant.apache.org/?referer=');">Apache Ant</a> on your system. Ant will already be installed if you have installed the Mac OS X Developer Tools (which are an optional install included with every version of OS X) or are running Leopard.
<p>Open Terminal and type:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">whereis</span> ant</pre></div></div>

<p>It should say something like</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ant</pre></div></div>

<p>If Ant is not installed, no path will be shown in Terminal. To install Ant I recommend using MacPorts, an excellent open source utility for managing unix tools on Mac OS X (follow these well written <a href="http://2tbsp.com/content/easily_manage_unix_packages_mac_macports,_formerly_darwinports" onclick="pageTracker._trackPageview('/outgoing/2tbsp.com/content/easily_manage_unix_packages_mac_macports_formerly_darwinports?referer=');">directions for installation</a>). If you are not comfortable using the Terminal, there is a GUI available for MacPorts called <a href="http://porticus.alittledrop.com" onclick="pageTracker._trackPageview('/outgoing/porticus.alittledrop.com?referer=');">Porticus</a>.</li>
<li>Copy the Flex Ant tasks to your Ant installation&#8217;s library. These will allow Ant to communicate with the major Flex SDK tools. To copy the tasks, first locate the Ant <code>lib</code> directory, which will be in Ant&#8217;s main installation folder. For example on Mac OS X 10.5 it appears at <code>usr/share/ant/lib</code>. Copy <code>/Applications/flex_sdk_3/ant/lib/flexTasks.jar</code> into this directory.
</li>
<li>
If you are an advanced user and would like to utilize Unit Testing using FlexUnit, <a href="http://weblogs.macromedia.com/pmartin/tooling/flexunit/FlexAntTasks.jar" onclick="pageTracker._trackPageview('/outgoing/weblogs.macromedia.com/pmartin/tooling/flexunit/FlexAntTasks.jar?referer=');">Download the FlexUnit Ant Tasks</a>. Place these in the Ant installation&#8217;s library folder as well. </p>
<p>(Note: The project template you will download from my site in the next step includes two SWCs for use with unit testing. For those that may be curious where these came from, here are the links to the original locations: <a href="http://opensource.adobe.com/wiki/display/flexunit/Downloads" onclick="pageTracker._trackPageview('/outgoing/opensource.adobe.com/wiki/display/flexunit/Downloads?referer=');">FlexUnit SWC library</a> and <a href="http://weblogs.macromedia.com/pmartin/tooling/flexunit/FlexUnitOptional-bin.zip" onclick="pageTracker._trackPageview('/outgoing/weblogs.macromedia.com/pmartin/tooling/flexunit/FlexUnitOptional-bin.zip?referer=');">FlexUnit Optional SWC library</a>)
</li>
<li><a href='/wp-content/uploads/2009/01/flexsdkprojecttemplate.zip'>Download the Flex SDK example application template</a> from my site. Unzip the archive and place the <code>FlexSDKProjectTemplate</code> folder on your desktop. Open the folder.</li>
<li>
Make a copy of  <code>build.properties.template</code> and rename it <code>build.properties</code>.
</li>
<li>
Open the <code>build.properties</code> file you just created and edit the <code>REQUIRED TOOL LOCATIONS</code> section to reflect the path to the Flex SDK, your preferred web browser, and the location of the Flash Player (which you will need to <a href="http://www.adobe.com/support/flashplayer/downloads.html" onclick="pageTracker._trackPageview('/outgoing/www.adobe.com/support/flashplayer/downloads.html?referer=');">download</a> if you have not already done so).
</li>
<li>Using Terminal navigate to the example application template. For example:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> Desktop<span style="color: #000000; font-weight: bold;">/</span>FlexSDKProjectTemplate<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>And then type the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ant run</pre></div></div>

<p>The sample application will launch, typing <code>ant usage</code> will show you what other options are available, such as creating documentation, SWCs, or launching the application in a web browser.
</li>
<li>
Lastly, to enable the <code>trace()</code> method so that it will work from your code when using the Flash debug player, create a textfile called <code>mm.cfg</code> and fill it with the following:</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">TraceOutPutFileName=flashlog.txt
ErrorReportingEnable=1
TraceOutputFileEnable=1
MaxWarnings=0</pre></div></div>

<p>Place this file at <code><br />
/Library/Application Support/Macromedia/mm.cfg</code>. Whenever you have a <code>trace("some text");</code> statement in your code, it will be written to:</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">/Users/[your username]/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt</pre></div></div>

</li>
</ol>
<p>Please leave comments with any suggestions, problems, questions, etc. Enjoy!</p>
<h4>Troubleshooting</h4>
<p><b>Problem:</b> Running ASDoc produces: <code>Execute failed: java.io.IOException: /Applications/flex_sdk_3/bin/asdoc: cannot execute</code></p>
<p><b>Solution:</b> This mostly likely means the ASDoc script Ant uses is not set to be executable. Type the following in Terminal:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>flex_sdk_3<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x asdoc</pre></div></div>

<p>The first line changes the directory to the one ASDoc resides in. The second line makes ASDoc executable.</p>
<p><b>Problem:</b> Running ASDoc produces: <code>exec returned: 255</code></p>
<p><b>Solution:</b> This mostly likely means the ASDoc script (which is just a text file) contains Window-style line endings. These will need to be converted to linux. </p>
<p>Install dos2unix using MacPorts and type the following in Terminal:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>flex_sdk_3<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>
dos2unix asdoc</pre></div></div>

<p>This will turn off the executable bit in the permission tables, so you will have to re-enable that using the instructions in the first solution above.</p>
<p><b>Problem:</b> Running ASDoc produces: <code>Could not create toplevel.xml: /Applications/flex_sdk_3/asdoc/templates/asDocHelper: cannot execute</code></p>
<p><b>Solution:</b> This mostly likely means that a helper script used by ASDoc is not set to be executable. Type the following in Terminal:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>flex_sdk_3<span style="color: #000000; font-weight: bold;">/</span>asdoc<span style="color: #000000; font-weight: bold;">/</span>templates<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x asDocHelper</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.anselmbradford.com/2009/01/06/curious-about-adobe-open-source-get-started-with-the-flex-sdk-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

