<?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 World In A State of Flex &#187; Best Practices</title>
	<atom:link href="http://unitedmindset.com/jonbcampos/category/development/best-practices/feed/" rel="self" type="application/rss+xml" />
	<link>http://unitedmindset.com/jonbcampos</link>
	<description>Jonathan Campos&#039;s Blog about Flex and the Flash Platform</description>
	<lastBuildDate>Thu, 29 Jul 2010 15:46:38 +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>Practical Performance Tweaks</title>
		<link>http://unitedmindset.com/jonbcampos/2009/11/30/practical-performance-tweaks/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=practical-performance-tweaks</link>
		<comments>http://unitedmindset.com/jonbcampos/2009/11/30/practical-performance-tweaks/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 16:02:39 +0000</pubDate>
		<dc:creator>Jonathan Campos</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[performance testing]]></category>

		<guid isPermaLink="false">http://unitedmindset.com/jonbcampos/?p=1018</guid>
		<description><![CDATA[I&#8217;ve had a little bit of time on my hands in my day job *cough choke laugh* and thought I would spend some time doing some low level improvements on the performance of my applications. Though there were some changes I made that might have improved the performance of a function by a few milliseconds [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had a little bit of time on my hands in my day job *cough choke laugh* and thought I would spend some time doing some low level improvements on the performance of my applications. Though there were some changes I made that might have improved the performance of a function by a few milliseconds on average there were a few things that I changed that made large improvements. These are the sorts of fixes that you commit to memory and just always keep them as time moves forward.</p>
<p>I&#8217;m not talking about making sure that you removeEventListeners and nullify unused objects for garbage collection, that is a given. These are common tweaks that people could use in every application but often we don&#8217;t because we suspect that the performance hit isn&#8217;t as big as it is. Here we will look at how big that hit actually is.<br />
<span id="more-1018"></span><br />
For all these tests I used <a href="http://www.gskinner.com/blog/archives/2009/04/as3_performance.html">Grant Skinner&#8217;s Performance Testing Harness</a>. The numbers for the tests are provided along with the source code and the test available to run. I slightly modified the Testing Harness so that I could also get the times and numbers out of each test for graphing purposes.</p>
<p><strong>Array vs ArrayCollection vs ICollectionView</strong><br />
These tests all started when I wondered how much slower iterating through an ArrayCollection was than iterating through an Array. The numbers were staggering. In some cases, iterating through the Array was <strong>1/50th</strong> of the time or <strong>5000% faster</strong>.</p>
<p>For my test I also was curious if using an interface instead of using the actual object made a difference. As you can see from the numbers that the difference wasn&#8217;t hugely significant, but actual.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.ArraysTest (5 iterations) &nbsp; &nbsp; &nbsp;<br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different array tests. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
findLastArray &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 81 &nbsp; &nbsp;16.20<br />
findLastArrayCollection &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4484 &nbsp; 896.80<br />
findLastICollectionView &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4405 &nbsp; 881.00<br />
findLastVector &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 106 &nbsp; &nbsp;21.20<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<p>One rumor that I heard was that ArrayCollections are faster at finding a specific index value than Array&#8217;s due to some sort of magical optimization. So I tested that rumor also, below are the results. As you will see, this rumor is false. Arrays are faster at accessing a specific index value than ArrayCollections.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.ArraysTest (5 iterations) &nbsp; &nbsp; &nbsp;<br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different array tests. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
findObjectAtArray &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 64 &nbsp; &nbsp;12.80<br />
findObjectAtArrayCollectionOperand &nbsp; &nbsp; &nbsp; &nbsp;4200 &nbsp; 840.00<br />
findObjectAtArrayCollectionGetItemAt &nbsp; &nbsp; &nbsp;1700 &nbsp; 340.00<br />
findObjectAtICollectionView &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4151 &nbsp; 830.20<br />
findObjectAtVector &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;84 &nbsp; &nbsp;16.80<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<p>Already there are additional tests I am thinking about running, but on the whole you can see that using the base Array over ArrayCollection will yield large performance improvements. </p>
<p>However, I again want to point out that whenever you set an Array as the dataProvider of a Flex component, Flex components convert Arrays to ArrayCollections. So don&#8217;t try to get a performance increase from a component specifically by setting the dataProvider as an Array, the Array will be transformed either way.</p>
<p><strong>Loops</strong><br />
The next section that I was going to test was the age old debate about the perfect loop: For Loops vs While Loops, iterating before the loop vs after the loop, etc etc. Luckily for me, as soon as I started looking at Grant&#8217;s testing harness, he had already created most of the test cases for me (Thanks). So the only extension to the test that I had to make was to also test against iterating before or after the loop (++i vs i++). The results can be seen below.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.LoopsTest (5 iterations) &nbsp; &nbsp; &nbsp; <br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different loop structures. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
forIncrementAfter &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;439 &nbsp; &nbsp;87.80<br />
forDecrementAfter &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;439 &nbsp; &nbsp;87.80<br />
forIncrementBefore &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 445 &nbsp; &nbsp;89.00<br />
forDecrementBefore &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 435 &nbsp; &nbsp;87.00<br />
* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
whileIncrementAfter &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;647 &nbsp; 129.40<br />
whileDecrementAfter &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;456 &nbsp; &nbsp;91.20<br />
whileIncrementBefore &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 649 &nbsp; 129.80<br />
whileDecrementBefore &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 456 &nbsp; &nbsp;91.20<br />
* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
doWhileIncrementAfter &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;465 &nbsp; &nbsp;93.00<br />
doWhileDecrementAfter &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;480 &nbsp; &nbsp;96.00<br />
doWhileIncrementBefore &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 483 &nbsp; &nbsp;96.60<br />
doWhileDecrementBefore &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 479 &nbsp; &nbsp;95.80<br />
* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
forIn &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;623 &nbsp; 124.60<br />
forEachIn &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;669 &nbsp; 133.80<br />
forEachInUntyped &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 647 &nbsp; 129.40<br />
forEachInPosttyped &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1255 &nbsp; 251.00<br />
* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
arrForEach &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1722 &nbsp; 344.40<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<p>What you will probably notice is that no specific loop includes massive performance improvements, though the simple for loop seemed to be the fastest on average. So take your pick and run with it. </p>
<p><strong>Unrolled Loops</strong><br />
The next tests that I came up with was to see how efficient rolled vs unrolled loops were. The reason I felt this was important is there are times that we needlessly iterate through a loop when we know there will always be X number of elements. When this is a the case I&#8217;ve found (and the tests prove) that it is faster to just do what you need with the X elements rather than write a loop to iterate through the elements.</p>
<p>Remember to check the source to see the implementations of these different tests.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.LoopsTest (5 iterations) &nbsp; &nbsp; &nbsp; <br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different loop structures. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
rolledUpLoop &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1585 &nbsp; 317.00<br />
unRolledLoop &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 864 &nbsp; 172.80<br />
rolledUpLongLoop &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1134 &nbsp; 226.80<br />
unRolledUpLongLoop &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 803 &nbsp; 160.60<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<p><strong>Length Reference Variable</strong><br />
This is definitely a nit picky test, but I had to know the truth! When iterating through a loop is it significantly better to get a reference to the length of the loop, or is it okay just to use <em>array.length</em> in each iteration. As proven, using a variable to store the length is significantly better.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.LoopsTest (5 iterations) &nbsp; &nbsp; &nbsp; <br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different loop structures. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
lengthReferenceTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;512 &nbsp; 102.40<br />
noLengthReferenceTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;926 &nbsp; 185.20<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<p><strong>Reference Variables</strong><br />
When iterating through a loop I often like to pull a reference to the current value that is being evaluated in a loop. I do this mainly to make reading the code easier, but I was curious if this creation of a new reference would be harmful to performance. On top of that I was curious if giving these temporary variables a type was helpful for performance or not. Below are the results.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.LoopsTest (5 iterations) &nbsp; &nbsp; &nbsp; <br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different loop structures. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
noTemporaryLoopVariableUntyped &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1988 &nbsp; 397.60<br />
noTemporaryLoopVariableTyped &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1937 &nbsp; 387.40<br />
temporaryLoopVariableUntyped &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1849 &nbsp; 369.80<br />
temporaryLoopVariableTyped &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1897 &nbsp; 379.40<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<p>As you can see I&#8217;ve figured that there isn&#8217;t a significant performance increase or loss with using temporary variables. I think I&#8217;ll keep using my temporary variables to make reading easier.</p>
<p><strong>Type, Cast and toX</strong><br />
The next series of tests are extremely geeky tests with some startling results. Is it faster to say <em>(object as String)</em> or <em>String(object)</em> or <em>object.toString</em>? This test case and many others are included below for each of the base types. May this help you decide how to type and cast your variables.</p>
<p>The big one to notice is the amount of time it takes to <em>String(number)</em> instead of saying <em>(number as String)</em>.</p>
<p>Included with each test is the control case of casting and typing each type to the same base type.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.TypesTest (5 iterations) &nbsp; &nbsp; &nbsp; <br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different type, casting, and manipulation tests. &nbsp;<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
stringToString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;96 &nbsp; &nbsp;19.20<br />
stringCastString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;68 &nbsp; &nbsp;13.60<br />
stringAsString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;76 &nbsp; &nbsp;15.20<br />
objectStringToString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 153 &nbsp; &nbsp;30.60<br />
objectStringCastString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;70 &nbsp; &nbsp;14.00<br />
objectStringAsString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;78 &nbsp; &nbsp;15.60<br />
numberCastString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 888 &nbsp; 177.60<br />
numberAsString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 104 &nbsp; &nbsp;20.80<br />
intCastString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;229 &nbsp; &nbsp;45.80<br />
intAsString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 86 &nbsp; &nbsp;17.20<br />
uIntCastString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 229 &nbsp; &nbsp;45.80<br />
uIntAsString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;86 &nbsp; &nbsp;17.20<br />
* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
numberCastNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;46 &nbsp; &nbsp; 9.20<br />
numberAsNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 103 &nbsp; &nbsp;20.60<br />
objectNumberCastNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;50 &nbsp; &nbsp;10.00<br />
objectNumberAsNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;81 &nbsp; &nbsp;16.20<br />
intCastNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 46 &nbsp; &nbsp; 9.20<br />
intAsNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 84 &nbsp; &nbsp;16.80<br />
uIntCastNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;46 &nbsp; &nbsp; 9.20<br />
uIntAsNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;86 &nbsp; &nbsp;17.20<br />
stringCastNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;76 &nbsp; &nbsp;15.20<br />
stringAsNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;84 &nbsp; &nbsp;16.80<br />
* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
uintCastUint &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;45 &nbsp; &nbsp; 9.00<br />
uintAsUint &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;86 &nbsp; &nbsp;17.20<br />
objectUintCastUint &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;48 &nbsp; &nbsp; 9.60<br />
objectUintAsUint &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;82 &nbsp; &nbsp;16.40<br />
numberCastUint &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;47 &nbsp; &nbsp; 9.40<br />
numberAsUint &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 113 &nbsp; &nbsp;22.60<br />
intCastUint &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 45 &nbsp; &nbsp; 9.00<br />
intAsUint &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 84 &nbsp; &nbsp;16.80<br />
stringCastUint &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;82 &nbsp; &nbsp;16.40<br />
stringAsUint &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;90 &nbsp; &nbsp;18.00<br />
* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
intCastInt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;46 &nbsp; &nbsp; 9.20<br />
intAsInt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;82 &nbsp; &nbsp;16.40<br />
objectIntCastInt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;48 &nbsp; &nbsp; 9.60<br />
objectIntAsInt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;80 &nbsp; &nbsp;16.00<br />
numberCastInt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 47 &nbsp; &nbsp; 9.40<br />
numberAsInt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;106 &nbsp; &nbsp;21.20<br />
uintCastInt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 46 &nbsp; &nbsp; 9.20<br />
uintAsInt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 86 &nbsp; &nbsp;17.20<br />
stringCastInt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 77 &nbsp; &nbsp;15.40<br />
stringAsInt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 88 &nbsp; &nbsp;17.60<br />
* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
arrayAsArray &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;77 &nbsp; &nbsp;15.40<br />
objectArrayAsArray &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;81 &nbsp; &nbsp;16.20<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<blockquote><p>Remember when using &#8220;as&#8221;, if the conversion fails, you will receive a null rather than the value. Unless you explicitly know what the type will be, it is always good to make this check.</p></blockquote>
<p><strong>The &#8220;new&#8221; operator</strong><br />
I&#8217;ve always been told that when creating a new base type that you should use the value rather than <em>new</em> because it saves the need for the VM to allocate the memory in the heap. But what was the ACTUAL performance improvements. Again, the numbers are staggering. For the next tests I created each of the simple types 3 different ways. </p>
<p>The first way I used the <em>new</em> operator as such: var s:String = new String();<br />
The second way I used the new value as such: var s:String = &#8220;&#8221;;<br />
And the final test was to create the variable with the <em>new</em> operator without the final parenthesis, such as: var s:String = new String;</p>
<p>For every test setting the value rather than using the <em>new</em> operator was almost twice as fast. The biggest difference being with creating a new Array, using the <em>[]</em> operand instead of the <em>new</em> operator was almost 3 times as fast.</p>
<p>I should also point out that for almost each test, using the parenthesis was slower than leaving them off when creating a new variable, though this is considered bad practice. Though the difference was marginal.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.TypesTest (5 iterations) &nbsp; &nbsp; &nbsp; <br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different type, casting, and manipulation tests. &nbsp;<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
newUintTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 75 &nbsp; &nbsp;15.00<br />
newUintValueTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;44 &nbsp; &nbsp; 8.80<br />
newUintTestNoParams &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 76 &nbsp; &nbsp;15.20<br />
* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
newIntTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;75 &nbsp; &nbsp;15.00<br />
newIntValueTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 45 &nbsp; &nbsp; 9.00<br />
newIntTestNoParams &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;74 &nbsp; &nbsp;14.80<br />
* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
newNumberTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 72 &nbsp; &nbsp;14.40<br />
newNumberValueTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;45 &nbsp; &nbsp; 9.00<br />
newNumberTestNoParams &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 75 &nbsp; &nbsp;15.00<br />
* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
newStringTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 71 &nbsp; &nbsp;14.20<br />
newStringValueTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;45 &nbsp; &nbsp; 9.00<br />
newStringTestNoParams &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 74 &nbsp; &nbsp;14.80<br />
* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
newArrayTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 711 &nbsp; 142.20<br />
newArrayValueTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;249 &nbsp; &nbsp;49.80<br />
newArrayTestNoParams &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 709 &nbsp; 141.80<br />
* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
newObjectTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;267 &nbsp; &nbsp;53.40<br />
newObjectValueTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 230 &nbsp; &nbsp;46.00<br />
newObjectTestNoParams &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;263 &nbsp; &nbsp;52.60<br />
* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
newXMLTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1032 &nbsp; 206.40<br />
newXMLValueTest &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1023 &nbsp; 204.60<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<p><strong>Static Methods vs Class Methods</strong><br />
As a side curiosity I was wanted to know if there was any performance loss or gain based on the types of functions used within a class. I was able to see that there weren&#8217;t any significant performance improvements over one type of function or another. So stick with best practices within your classes and only make methods and properties public when they absolutely have to be.</p>
<p>This test does not include testing whether creating the class and then accessing the function is better than a static function which does not need to instantiate a class.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.ClassTest (5 iterations) &nbsp; &nbsp; &nbsp; <br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different class method tests. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
publicMethod &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 141 &nbsp; &nbsp;28.20<br />
privateMethod &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;143 &nbsp; &nbsp;28.60<br />
protectedMethod &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;144 &nbsp; &nbsp;28.80<br />
publicStaticMethod &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 141 &nbsp; &nbsp;28.20<br />
privateStaticMethod &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;142 &nbsp; &nbsp;28.40<br />
protectedStaticMethod &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;141 &nbsp; &nbsp;28.20<br />
publicInternalMethod &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 142 &nbsp; &nbsp;28.40<br />
publicFinalMethod &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;144 &nbsp; &nbsp;28.80<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<p><strong>Using &#8220;this&#8221; and Other Class Curiosities</strong><br />
This next section includes many different tests to improve my class creation.</p>
<p><strong>Setting the default values</strong><br />
In this test I was curious if it is better to initially set a variable in the constructor or at the variable, and also if setting the variable defaults inside the class vs outside the class was better. What I found is that it is faster to initially just set the variables to their default value rather than making this change in the constructor.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.VariablesTest (5 iterations) &nbsp; <br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different variables and vo based tests. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
defaultVarsSetVO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 400 &nbsp; &nbsp;80.00<br />
varsSetInConstructorVO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 490 &nbsp; &nbsp;98.00<br />
varsSetOutsideConstructorThisVO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;499 &nbsp; &nbsp;99.80<br />
varsSetOutsideConstructorNoThisVO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;496 &nbsp; &nbsp;99.20<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<p><strong>Is using &#8220;this&#8221; wrong?</strong><br />
Checking whether it was faster to use the &#8220;this&#8221; identifier was harmful to performance I concluded that there was no significant performance loss or gain in using the &#8220;this&#8221; identifier.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.VariablesTest (5 iterations) &nbsp; <br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different variables and vo based tests. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
thisToString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2395 &nbsp; 479.00<br />
noThisToString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2441 &nbsp; 488.20<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<p><strong>Getters and Setters vs Direct Accessors</strong><br />
Lots of good ole&#8217; boy Java developers will tell you that every property has to have a getter and setter. Other programmers will say that this is only necessary if there is some logic that needs to run in the get/set process. Now you can see that by using a getter/setter when a direct accessor can be used is wasteful for performance and typing. Therefore, only create getters/setters when it is important to run some logic in the getting/setting process.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.VariablesTest (5 iterations) &nbsp; <br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different variables and vo based tests. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
noGetSetAccessors &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2382 &nbsp; 476.40<br />
getSetAccessors &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2786 &nbsp; 557.20<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<p><strong>Size really doesn&#8217;t matter&#8230; in variables.</strong><br />
Finally, the stigma from writing Javascript applications always left me feeling guilty about using full words when a letter can do. In Javascript this was a performance issue and caused many programmers to use single incomprehensible letters instead of easy to read words. To elevate my guilt I decided to test if using long variable names made any difference at runtime. The answer is no. No savings, no loss. Now, guilt free, I will always use well written variable names instead of short single letter descriptors.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.VariablesTest (5 iterations) &nbsp; <br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different variables and vo based tests. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
shortVarNames &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 45 &nbsp; &nbsp; 9.00<br />
longVarNames &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;45 &nbsp; &nbsp; 9.00<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<p><strong>If..Then vs Switch..Case</strong><br />
Like loops, developers argue which logical test is better: <em>if..then</em> vs <em>switch..case</em>. Pitting the two against each other, apples vs apples, I&#8217;ve found that <em>if..then</em> statements are slightly faster than <em>switch..case</em> statements. I will still use each statement where appropriate though, but it is good to know in the situations that I have the choice that I should use <em>if..then</em> statements.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.LogicalTest (5 iterations) &nbsp; &nbsp; <br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different logical structure tests. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
switchCaseStatement &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;411 &nbsp; &nbsp;82.20<br />
ifThenElseStatement &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;378 &nbsp; &nbsp;75.60<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<p><strong>Math.max() vs Math.max.apply()</strong><br />
One little known secret to AS3 is the apply method. Most classes have more than one way to skin a cat, and the apply method is that function. In the case of <em>Math.max</em> (or <em>Math.min</em>) I was curious how much faster the apply method was vs logically finding the largest (or smallest) value. The numbers were staggering. From now on I will be using the apply method whenever possible as it is a very low level and fast function.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
com.unitedmindset.tests.ApplyTest (5 iterations) &nbsp; &nbsp; &nbsp; <br />
Player version: MAC 10,0,32,18 (debug)<br />
Test different apply method tests. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––<br />
method..................................ttl ms...avg ms<br />
findMaxLogically &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2093 &nbsp; 418.60<br />
findMaxApply &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 131 &nbsp; &nbsp;26.20<br />
–––––––––––––––––––––––––––––––––––––––––––––––––––––––</div></td></tr></tbody></table></div>
<p><strong>Final Thoughts</strong><br />
Obviously the things in this list I see as some of the greatest offenders and also the easiest to fix. It all comes down to you and which changes you feel comfortable making in your daily coding practices. Some of the more &#8220;nit picky&#8221; performance changes I feel can effect code readability and reusability, and which you implement into your code is up to you and your coding practices. Hopefully this ends the debate between some techniques as being the end all be all technique.</p>
<p>If there are other coding techniques that have left you wondering which is better, let me know and I&#8217;ll add it in. I&#8217;m sure over time I&#8217;ll revisit these test cases.</p>
<p><strong>The Test, Run It For Yourself Or View Source</strong><br />

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="800" height="650">
      <param name="movie" value="http://unitedmindset.com/jonbcampos/wp-content/flex_content/performance/PerformanceApp.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://unitedmindset.com/jonbcampos/wp-content/flex_content/performance/PerformanceApp.swf" width="800" height="650">
      <!--<![endif]-->
        If you are having a hard time viewing this test app go get flash. Or try the direct link, &lt;a href=&quot;http://unitedmindset.com/jonbcampos/wp-content/flex_content/performance/PerformanceApp.html&quot;&gt;Performance Test App&lt;/a&gt;
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br />
<a href="http://unitedmindset.com/jonbcampos/wp-content/flex_content/performance/srcview/index.html">View Source</a> (or right click swf)</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://unitedmindset.com/jonbcampos/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://unitedmindset.com/jonbcampos/2009/11/30/practical-performance-tweaks/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Getting Through Black Magic: Font Embedding</title>
		<link>http://unitedmindset.com/jonbcampos/2009/11/24/getting-through-black-magic-font-embedding/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=getting-through-black-magic-font-embedding</link>
		<comments>http://unitedmindset.com/jonbcampos/2009/11/24/getting-through-black-magic-font-embedding/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 15:59:40 +0000</pubDate>
		<dc:creator>Jonathan Campos</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[font embedding]]></category>
		<category><![CDATA[unicode ranges]]></category>

		<guid isPermaLink="false">http://unitedmindset.com/jonbcampos/?p=1022</guid>
		<description><![CDATA[Be it in Fx2, Fx3 or Fx4, Font Embedding is an integral part of any application due to the annoying issues you will start running into by just using device fonts. And once you get your embedded font into the application you&#8217;ll never look back at the issue, but getting the embedded font into the [...]]]></description>
			<content:encoded><![CDATA[<p>Be it in Fx2, Fx3 or Fx4, Font Embedding is an integral part of any application due to the annoying issues you will start running into by just using device fonts. And once you get your embedded font into the application you&#8217;ll never look back at the issue, but getting the embedded font into the application seems bring some developers to their knees.</p>
<p>There are two main ways that I see people embed fonts.</p>
<p>1) Straight @font-face embed via Flex CSS<br />
2) Embedding the font into a Flash File, selecting the glyphs to embed, and then embedding the resulting SWF into Flex.</p>
<p>People use the first one for simplicity and the second (definitely more difficult route) for optimization. Yet people keep forgetting (or never knew) that there is a third route that provides simplicity and optimization.<br />
<span id="more-1022"></span><br />
<strong>First, the basics&#8230;</strong><br />
In your Flex CSS file (or in the style block) start up a new font face block.</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">@</span>font-face <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Next provide a direct path from your application&#8217;s root folder to the font. For ease I usually make a copy of the font and stick it in my assets folder so that other people connected to my project can still build the app.</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">@</span>font-face <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;src: <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/fonts/verdana.ttf&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now name the new font-face so it can be referenced as a font family.</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">@</span>font-face <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;src: <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/fonts/verdana.ttf&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;fontFamily: verdanaEmbed;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Next you need to add some description to the font. Is it a normal font?</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">@</span>font-face <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;src: <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/fonts/verdana.ttf&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;fontFamily: verdanaEmbed;<br />
&nbsp; &nbsp; &nbsp;fontStyle: normal;<br />
&nbsp; &nbsp; &nbsp;fontWeight: normal;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Bold</strong>?</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">@</span>font-face <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;src: <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/fonts/verdanab.ttf&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;fontFamily: verdanaEmbed;<br />
&nbsp; &nbsp; &nbsp;fontStyle: normal;<br />
&nbsp; &nbsp; &nbsp;fontWeight: <span style="color: #0066CC;">bold</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p><em>Italic</em>?</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">@</span>font-face <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;src: <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/fonts/verdanai.ttf&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;fontFamily: verdanaEmbed;<br />
&nbsp; &nbsp; &nbsp;fontStyle: <span style="color: #0066CC;">italic</span>;<br />
&nbsp; &nbsp; &nbsp;fontWeight: normal;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p><em><strong>Bold and Italic?</strong></em></p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">@</span>font-face <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;src: <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/fonts/verdanaz.ttf&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;fontFamily: verdanaEmbed;<br />
&nbsp; &nbsp; &nbsp;fontStyle: <span style="color: #0066CC;">italic</span>;<br />
&nbsp; &nbsp; &nbsp;fontWeight: <span style="color: #0066CC;">bold</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>To have all four of these options you would need to embed each of the different fonts that include all these options. They can all be under the same fontFamily name, but with different configurations. But if you are missing the <strong>bold</strong> font and trying to make your text <strong>bold</strong> you will not be getting the desired look. </p>
<p>If you are confused at all by the different @font-face blocks below make sure to look at the actually font file name. You will notice each is just slightly different with the different look.</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">@</span>font-face <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;src: <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/fonts/verdana.ttf&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;fontFamily: verdanaEmbed;<br />
&nbsp; &nbsp; &nbsp;fontStyle: normal;<br />
&nbsp; &nbsp; &nbsp;fontWeight: normal;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #66cc66;">@</span>font-face <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;src: <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/fonts/verdanab.ttf&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;fontFamily: verdanaEmbed;<br />
&nbsp; &nbsp; &nbsp;fontStyle: normal;<br />
&nbsp; &nbsp; &nbsp;fontWeight: <span style="color: #0066CC;">bold</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #66cc66;">@</span>font-face <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;src: <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/fonts/verdanai.ttf&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;fontFamily: verdanaEmbed;<br />
&nbsp; &nbsp; &nbsp;fontStyle: <span style="color: #0066CC;">italic</span>;<br />
&nbsp; &nbsp; &nbsp;fontWeight: normal;<br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #66cc66;">@</span>font-face <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;src: <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/fonts/verdanaz.ttf&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;fontFamily: verdanaEmbed;<br />
&nbsp; &nbsp; &nbsp;fontStyle: <span style="color: #0066CC;">italic</span>;<br />
&nbsp; &nbsp; &nbsp;fontWeight: <span style="color: #0066CC;">bold</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Next you need to set whether your font is using advanced anti aliasing. This takes slightly more processing, but can make your fonts look nicer at larger sizes. This is dependent also on whether the font type supports it. Usually, I just set this to <em>true</em>.</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">@</span>font-face <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;src: <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/fonts/verdana.ttf&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;fontFamily: verdanaEmbed;<br />
&nbsp; &nbsp; &nbsp;fontStyle: normal;<br />
&nbsp; &nbsp; &nbsp;fontWeight: normal;<br />
&nbsp; &nbsp; &nbsp;advancedAntiAliasing: <span style="color: #000000; font-weight: bold;">true</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now with Fx4 you have something new to worry about: CFF. If this is set to true, the font will be available to the new TLF engine and Fx4 (Spark) components. If CFF is set to false then it will be available to Fx3 (Halo) components. Yes, right now you need to embed two fonts to get this to work for both. In the future this may change.</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">@</span>font-face <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;src: <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/fonts/verdana.ttf&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;fontFamily: verdanaEmbed;<br />
&nbsp; &nbsp; &nbsp;fontStyle: normal;<br />
&nbsp; &nbsp; &nbsp;fontWeight: normal;<br />
&nbsp; &nbsp; &nbsp;advancedAntiAliasing: <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp;cff: <span style="color: #000000; font-weight: bold;">true</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>And now, the optimization&#8230;</strong><br />
You may have hit some issues with all the previous steps, or not &#8211; but here is the optimizations. Within the @font-face tag you can set which unicode characters to embed &#8211; this is like selecting the glyphs in Flash. To find a helpful table of common unicode characters and ranges that people use refer back to your flex sdk, specifically: <em>flex-sdk-folder</em>/frameworks/flash-unicode-table.xml. After looking through the table you can select your desired ranges that you want included with the font embed. The more unicode characters the larger the final SWF file will be, the fewer, the smaller.<br />
My final @font-face embed statement.</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">@</span>font-face <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;src: <span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/assets/fonts/verdana.ttf&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;fontFamily: verdanaEmbed;<br />
&nbsp; &nbsp; &nbsp;fontStyle: normal;<br />
&nbsp; &nbsp; &nbsp;fontWeight: normal;<br />
&nbsp; &nbsp; &nbsp;advancedAntiAliasing: <span style="color: #000000; font-weight: bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp;cff: <span style="color: #000000; font-weight: bold;">true</span><br />
&nbsp; &nbsp; &nbsp;unicodeRange:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;U+0041-U+005A, <span style="color: #808080; font-style: italic;">/* Upper-Case [A..Z] */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;U+0061-U+007A, <span style="color: #808080; font-style: italic;">/* Lower-Case a-z */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;U+0030-U+0039, <span style="color: #808080; font-style: italic;">/* Numbers [0..9] */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;U+0020-U+002F,U+003A-U+0040,U+005B-U+0060,U+007B-U+007E; <span style="color: #808080; font-style: italic;">/* Puctuation */</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Profit!</strong><br />
That&#8217;s it, embedded and optimized fonts. I&#8217;ve actually tested the size of the resulting Flex App SWF files after going the long route and the route shown here. Both resulting sizes are exactly the same, down to the last byte.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://unitedmindset.com/jonbcampos/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://unitedmindset.com/jonbcampos/2009/11/24/getting-through-black-magic-font-embedding/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Lockable List and Tree</title>
		<link>http://unitedmindset.com/jonbcampos/2009/10/23/lockable-list-and-tree/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=lockable-list-and-tree</link>
		<comments>http://unitedmindset.com/jonbcampos/2009/10/23/lockable-list-and-tree/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 15:05:04 +0000</pubDate>
		<dc:creator>Jonathan Campos</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[custom component development]]></category>
		<category><![CDATA[custom components]]></category>

		<guid isPermaLink="false">http://unitedmindset.com/jonbcampos/?p=892</guid>
		<description><![CDATA[Anyone that knows me knows that I like making little test cases and components. Before I start showing off some of my custom spark components I wanted to make sure and share this custom component that I call the Lockable List. But, as every developer knows, when you have a list it is almost assured [...]]]></description>
			<content:encoded><![CDATA[<p>Anyone that knows me knows that I like making little test cases and components. Before I start showing off some of my custom spark components I wanted to make sure and share this custom component that I call the <em>Lockable Lis</em>t. But, as every developer knows, when you have a list it is almost assured that you will need a tree. So I followed up with the list and built the <em>Lockable Tree</em>.<br />
<span id="more-892"></span><br />
I have left the source code and everything available for these components, but wanted to draw people&#8217;s attention to the itemrenderers here. This is where the real magic is. Yes there is some functionality to List and Tree components that I have added, but the item renderers are really what make things possible. The List and Tree mainly add a wrapper to the data that is set (so the itemrenderers can work off the data provided) and retreive the data back in it&#8217;s original manner. Pretty simple.</p>
<p>The itemrenderers are nice. Lightweight. Definitely check out the itemrenderer&#8217;s code. Very simple.</p>
<p>What these components do is &#8220;hold&#8221; or &#8220;lock&#8221; a selection. In these examples you may say &#8220;well that is similar to shift/ctrl select&#8221;. Yes and no. If you need to hold nodes that may become difficult in large lists and in my apps I do lots of list filtering and sorting, so now I can filter for a specific node AND keep locked nodes. Very helpful.</p>
<p>Special thank you to <a href="http://blog.killerspaz.com/">John Gorena</a> who already pointed out that this is something helpful for mobile development. Enjoy!</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_1" width="500" height="400" align="none">
      <param name="movie" value="http://unitedmindset.com/jonbcampos/wp-content/uploads/2009/10/LockableListApp.swf" />
      <param name="align" value="none" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://unitedmindset.com/jonbcampos/wp-content/uploads/2009/10/LockableListApp.swf" width="500" height="400" align="none">
      <!--<![endif]-->
        <a href='http://unitedmindset.com/jonbcampos/wp-content/flex_content/lockedlist/LockableListApp.html'>View Files Here</a>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>


    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_2" width="500" height="400" align="none">
      <param name="movie" value="http://unitedmindset.com/jonbcampos/wp-content/uploads/2009/10/LockableTreeApp.swf" />
      <param name="align" value="none" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://unitedmindset.com/jonbcampos/wp-content/uploads/2009/10/LockableTreeApp.swf" width="500" height="400" align="none">
      <!--<![endif]-->
        <a href='http://unitedmindset.com/jonbcampos/wp-content/flex_content/lockedlist/LockableTreeApp.html'>View Files Here</a>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://unitedmindset.com/jonbcampos/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://unitedmindset.com/jonbcampos/2009/10/23/lockable-list-and-tree/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MAX Presentation &#8211; Tackling Memory &amp; Performance in Flash, Flex, and AIR</title>
		<link>http://unitedmindset.com/jonbcampos/2009/10/08/max-presentation-tackling-memory-performance-in-flash-flex-and-air/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=max-presentation-tackling-memory-performance-in-flash-flex-and-air</link>
		<comments>http://unitedmindset.com/jonbcampos/2009/10/08/max-presentation-tackling-memory-performance-in-flash-flex-and-air/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 22:44:21 +0000</pubDate>
		<dc:creator>Jonathan Campos</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[air]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[max09]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://unitedmindset.com/jonbcampos/?p=777</guid>
		<description><![CDATA[Let&#8217;s start by saying thank you to everyone that attended my MAX presentation: Tackling Memory &#038; Performance with Flash, Flex, and AIR. This presentation was made possible by a joint effort of Jun Heider and myself. Below is a link to the Adobe.Tv recording of this presentation. This was a presentation that almost wasn&#8217;t though. [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s start by saying thank you to everyone that attended my MAX presentation: Tackling Memory &#038; Performance with Flash, Flex, and AIR. This presentation was made possible by a joint effort of <a href="http://iheartair.com/">Jun Heider</a> and myself. Below is a link to the Adobe.Tv recording of this presentation.</p>
<p><object width="425" height="256"><param name="movie" value="http://images.tv.adobe.com//swf/player.swf"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="FlashVars" value="fileID=2445&#038;context=162&#038;embeded=true&#038;environment=production"></param><embed src="http://images.tv.adobe.com//swf/player.swf" flashvars="fileID=2445&#038;context=162&#038;embeded=true&#038;environment=production" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="256"></embed></object><br />
<span id="more-777"></span><br />
This was a presentation that almost wasn&#8217;t though. For those who don&#8217;t know, this presentation was originally planned to be presented by <a href="http://craftymind.com">Sean Chistmann</a> of EffectiveUI, yet as he fell sick Adobe called Jun and myself to fill in the gap. Working closely with Jun and Sean (when available) we added our own personal touches to the presentation and presented on Tuesday and Wednesday of Max. Again, thank you to everyone that attended either of the sessions and all the great feedback we received.</p>
<p><a href='http://unitedmindset.com/jonbcampos/wp-content/uploads/2009/10/tacklingmemoryandperformance.pdf'>Tackling Memory and Performance in Flash, Flex, and AIR</a><br />
<a href='http://unitedmindset.com/jonbcampos/wp-content/uploads/2009/10/archive.zip'>Presentation Source Files</a></p>
<p>Below is a list of helpful resources for continued education in this subject:</p>
<p><strong>Livedocs</strong></p>
<ul>
<li><a href="http://livedocs.adobe.com/flex/gumbo/html/WS6f97d7caa66ef6eb1e63e3d11b6c4d0169-8000.html">http://livedocs.adobe.com/flex/gumbo/html/WS6f97d7caa66ef6eb1e63e3d11b6c4d0169-8000.html</a></li>
<li><a href="http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/flash/sampler/package-detail.html">http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/flash/sampler/package-detail.html</a></li>
</ul>
<p><strong>Flex Profiler and flash.sampler.* classes:</strong></p>
<ul>
<li><a href="http://blogs.adobe.com/aharui/2008/09/using_the_flex_builder_3x_prof.html">http://blogs.adobe.com/aharui/2008/09/using_the_flex_builder_3x_prof.html</a></li>
<li><a href="http://www.slideshare.net/srp1970/overview-of-flex-profiler/">http://www.slideshare.net/srp1970/overview-of-flex-profiler/</a></li>
<li><a href="http://lists.motion-twin.com/pipermail/haxe/2007-August/011362.html">http://lists.motion-twin.com/pipermail/haxe/2007-August/011362.html</a></li>
<li><a href="http://www.jinten.net/blog/archives/47">http://www.jinten.net/blog/archives/47</a></li>
<li><a href="http://ticore.blogspot.com/2008/05/as3-observe-object-size.html">http://ticore.blogspot.com/2008/05/as3-observe-object-size.html</a></li>
<li><a href="http://www.insideria.com/2008/06/profiling-flex-applications-sa.html">http://www.insideria.com/2008/06/profiling-flex-applications-sa.html</a></li>
<li><a href="http://stopcoding.wordpress.com/2008/04/26/lets-talk-about-the-flex-profiler/">http://stopcoding.wordpress.com/2008/04/26/lets-talk-about-the-flex-profiler/</a></li>
</ul>
<p><strong>AVM2 and MMgc:</strong></p>
<ul>
<li><a href="http://www.adobe.com/devnet/actionscript/articles/avm2overview.pdf">http://www.adobe.com/devnet/actionscript/articles/avm2overview.pdf</a></li>
<li><a href="http://developer.mozilla.org/en/docs/MMgc">http://developer.mozilla.org/en/docs/MMgc</a></li>
<li><a href="http://www.gskinner.com/blog/archives/2006/09/garbage_collect.html">http://www.gskinner.com/blog/archives/2006/09/garbage_collect.html</a></li>
</ul>
<p><strong>Performance and Memory Management:</strong></p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Performance_analysis">http://en.wikipedia.org/wiki/Performance_analysis</a></li>
<li><a href="http://en.wikipedia.org/wiki/Memory_management">http://en.wikipedia.org/wiki/Memory_management</a></li>
<li><a href="http://www.adobe.com/devnet/flashplayer/articles/resource_management.html">http://www.adobe.com/devnet/flashplayer/articles/resource_management.html</a></li>
<li><a href="http://www.slideshare.net/dcoletta/optimizing-flex-applications/">http://www.slideshare.net/dcoletta/optimizing-flex-applications/</a></li>
<li><a href="http://www.adobe.com/devnet/flex/articles/as3_tuning.html" class="broken_link">http://www.adobe.com/devnet/flex/articles/as3_tuning.html</a></li>
<li><a href="http://adobedev.adobe.acrobat.com/p71169528/">http://adobedev.adobe.acrobat.com/p71169528/</a></li>
<li><a href="http://www.insideria.com/jun-heider/">http://www.insideria.com/jun-heider/</a></li>
<li><a href="http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html">http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html</a></li>
<li><a href="http://blogs.adobe.com/aharui/2007/03/garbage_collection_and_memory.html">http://blogs.adobe.com/aharui/2007/03/garbage_collection_and_memory.html</a></li>
<li><a href="http://www.moock.org/blog/archives/000223.html">http://www.moock.org/blog/archives/000223.html</a></li>
<li><a href="http://blog.flexmonkeypatches.com/2007/03/28/flash-player-memory-management-and-garbagecollection-redux-2/" class="broken_link">http://blog.flexmonkeypatches.com/2007/03/28/flash-player-memory-management-and-garbagecollection-redux-2/</a></li>
<li><a href="http://olegfilipchuk.com/2009/07/24/unload-you-module/">http://olegfilipchuk.com/2009/07/24/unload-you-module/</a></li>
<li><a href="http://www.colettas.org/?p=115">http://www.colettas.org/?p=115</a></li>
</ul>
<p><strong>Data Transfer and Performance:</strong></p>
<ul>
<li><a href="http://www.jamesward.org/census">http://www.jamesward.org/census</a></li>
</ul>
<p><strong>Elastic Racetrack:</strong></p>
<ul>
<li><a href="http://www.onflex.org/ted/2005/07/flash-player-mental-model-elastic.php">http://www.onflex.org/ted/2005/07/flash-player-mental-model-elastic.php</a></li>
<li><a href="http://www.craftymind.com/2008/04/18/updated-elastic-racetrack-for-flash-9-and-avm2/">http://www.craftymind.com/2008/04/18/updated-elastic-racetrack-for-flash-9-and-avm2/</a></li>
</ul>
<p><strong>AIR/Flash Player Mac Idle CPU:</strong></p>
<ul>
<li><a href="http://www.gskinner.com/blog/archives/2009/05/idle_cpu_usage.html">http://www.gskinner.com/blog/archives/2009/05/idle_cpu_usage.html</a></li>
<li><a href="http://blogs.adobe.com/air/2009/05/performance_tips_for_adobe_air.html">http://blogs.adobe.com/air/2009/05/performance_tips_for_adobe_air.html</a></li>
</ul>
<p>Flexcoders:</p>
<ul>
<li><a href="http://www.mail-archive.com/flexcoders@yahoogroups.com/msg86385.html">http://www.mail-archive.com/flexcoders@yahoogroups.com/msg86385.html</a></li>
<li><a href="http://www.mail-archive.com/flexcoders@yahoogroups.com/msg83781.html">http://www.mail-archive.com/flexcoders@yahoogroups.com/msg83781.html</a></li>
<li><a href="http://www.mail-archive.com/flexcoders@yahoogroups.com/msg95073.html">http://www.mail-archive.com/flexcoders@yahoogroups.com/msg95073.html</a></li>
<li><a href="http://www.mail-archive.com/flexcoders@yahoogroups.com/msg92116.html">http://www.mail-archive.com/flexcoders@yahoogroups.com/msg92116.html</a></li>
<li><a href="http://www.mail-archive.com/flexcoders@yahoogroups.com/msg86738.html">http://www.mail-archive.com/flexcoders@yahoogroups.com/msg86738.html</a></li>
</ul>
<p><strong>Adobe Bugbase (Please vote for these bugs!):</strong></p>
<ul>
<li><a href="http://bugs.adobe.com/jira/browse/SDK-15731">http://bugs.adobe.com/jira/browse/SDK-15731</a></li>
<li><a href="https://bugs.adobe.com/jira/browse/SDK-14820">https://bugs.adobe.com/jira/browse/SDK-14820</a></li>
<li><a href="https://bugs.adobe.com/jira/browse/FP-2009">https://bugs.adobe.com/jira/browse/FP-2009</a></li>
<li><a href="https://bugs.adobe.com/jira/browse/SDK-14781">https://bugs.adobe.com/jira/browse/SDK-14781</a></li>
</ul>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://unitedmindset.com/jonbcampos/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://unitedmindset.com/jonbcampos/2009/10/08/max-presentation-tackling-memory-performance-in-flash-flex-and-air/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Flex Best Practices &#8211; Models, Views, and Controllers</title>
		<link>http://unitedmindset.com/jonbcampos/2009/08/18/flex-best-practices-models-views-and-controllers/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=flex-best-practices-models-views-and-controllers</link>
		<comments>http://unitedmindset.com/jonbcampos/2009/08/18/flex-best-practices-models-views-and-controllers/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 13:34:00 +0000</pubDate>
		<dc:creator>Jonathan Campos</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[controllers]]></category>
		<category><![CDATA[data models]]></category>
		<category><![CDATA[event dispatcher]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[Special Events]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://unitedmindset.com/jonbcampos/?p=677</guid>
		<description><![CDATA[If you read through this entire post and don&#8217;t see anything for you, congrats and ignore this next comment. No one seems to know how to actually implement MVC and I can&#8217;t stand it! Too many programs out there set up like a procedural php page (front top to bottom): imports, sql statements, data, methods, [...]]]></description>
			<content:encoded><![CDATA[<p>If you read through this entire post and don&#8217;t see anything for you, congrats and ignore this next comment.</p>
<p><strong>No one seems to know how to actually implement MVC and I can&#8217;t stand it!</strong></p>
<p>Too many programs out there set up like a procedural php page (front top to bottom): imports, sql statements, data, methods, and a ton of html. This is not how to set up a page, and even more so this isn&#8217;t how you set up an entire application! But people do it, don&#8217;t ask me how or why, but it&#8217;s a mess. </p>
<blockquote><p>
I want to let everyone know that the following &#8220;worst practice&#8221; example is actual code shown to me very recently. I simplified it a bit but ultimately the Flex application was one large mxml file.
</p></blockquote>
<p>You may try to argue that MVC takes more time to setup, more coding, &#8220;harder to read&#8221;, or whatever other arguments I have heard, but in the end it is easier to program, loosely coupled, simplistic, <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself" target="_blank">dry</a>, object oriented,  and finally <strong>best practice</strong>.<br />
<span id="more-677"></span><br />
If your code looks like this, you are doing it wrong! <strong>(Worst Practice)</strong></p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> <br />
&nbsp; &nbsp; xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/halo&quot;</span><br />
&nbsp; &nbsp; creationComplete=<span style="color: #ff0000;">&quot;application1_creationCompleteHandler(event)&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Alert</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">FaultEvent</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ResultEvent</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">FlexEvent</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> searchList:ArrayCollection = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span style="color: #000000; font-weight: bold;">function</span> application1_creationCompleteHandler<span style="color: #66cc66;">&#40;</span>event:FlexEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; runSearch<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> runSearch<span style="color: #66cc66;">&#40;</span>event:MouseEvent=<span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; httpService.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>searchTerm:searchInput.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span style="color: #000000; font-weight: bold;">function</span> httpService_resultHandler<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; searchList = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span> event.<span style="color: #006600;">result</span> as <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; protected <span style="color: #000000; font-weight: bold;">function</span> httpService_faultHandler<span style="color: #66cc66;">&#40;</span>event:FaultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; searchList = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;fault&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Script<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:HTTPService id=<span style="color: #ff0000;">&quot;httpService&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result=<span style="color: #ff0000;">&quot;httpService_resultHandler(event)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fault=<span style="color: #ff0000;">&quot;httpService_faultHandler(event)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resultFormat=<span style="color: #ff0000;">&quot;e4x&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">url</span>=<span style="color: #ff0000;">&quot;http://www.someUrl.com/yourMethod&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:VerticalLayout gap=<span style="color: #ff0000;">&quot;20&quot;</span> paddingBottom=<span style="color: #ff0000;">&quot;20&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;20&quot;</span> paddingRight=<span style="color: #ff0000;">&quot;20&quot;</span> paddingTop=<span style="color: #ff0000;">&quot;20&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HGroup <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:Label <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Search Term&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:TextInput <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> id=<span style="color: #ff0000;">&quot;searchInput&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Do It!&quot;</span> click=<span style="color: #ff0000;">&quot;runSearch(event)&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:HGroup<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">List</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<blockquote><p>This is an extremely simple example and honestly if this is all that your application needed to do then you are done. If your application is more complicated &#8211; or will get more complicated than this example &#8211; then this will fall apart real fast. <em>On top of that</em> good luck being able to unit test this code, reuse any of this code, using object oriented designs such as factories or even just interfaces, or even using the outliner view to find specific methods. Our final MVC application will be able to do all these things.</p></blockquote>
<p><strong>Quick Look At MVC</strong><br />
MVC is a simple concept that is immensely helpful at simplifying application development. The concept is just to split up your application by it&#8217;s model (the data), the view (what is seen), and the controller (the methods and functions that move the data from the view to the model and back).<br />
<a href="http://en.wikipedia.org/wiki/Model–view–controller" target="_blank">Wikipedia &#8211; MVC</a></p>
<p><strong>Understanding The Model</strong><br />
The models are your data centers for the application and extremely simple. In actionscript when you create models, this is the exact time you will want to use getters and setters for your properties. Why? Because the model just holds data and when the model has changed, it releases events to alert anything listening that the model has changed.</p>
<p><strong>Best Practices:</strong> All of the properties in your model should have setters and extend the EventDispatcher to be able to send out events when the model has changed. You can see what I mean in my model code below. You could always use custom events to send let your application know of property changes, but for my example I will just use the basic Event class. It is also <em>Best Practice</em> to check that the property has actually changed before sending out events and updating the value. Double check that the variable has actually changed first. Very easy with strings and numbers and such, a bit more effort for larger complex objects.</p>
<p><strong>Refactoring Your Code To The Model</strong><br />
For our example the model is EXTREMELY simple due to only one property, but you can see how simple the model is and how well it separates and simplifies the application layout. Finally you can now reuse this model in multiple controllers.</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">unitedmindset</span>.<span style="color: #006600;">models</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">EventDispatcher</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">IEventDispatcher</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Event<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;searchListChanged&quot;</span>,<span style="color: #0066CC;">type</span>=<span style="color: #ff0000;">&quot;flash.events.Event&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SampleModel <span style="color: #0066CC;">extends</span> EventDispatcher<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const SEARCH_LIST_CHANGED:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;searchListChanged&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SampleModel<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span>:IEventDispatcher=<span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _searchList:<span style="color: #0066CC;">Array</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> searchList<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> _searchList;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> searchList<span style="color: #66cc66;">&#40;</span>v:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _searchList = v;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #66cc66;">&#40;</span>SEARCH_LIST_CHANGED<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Understanding The Controller</strong><br />
Controllers are nothing more than a class that contains methods to move data back and forth from the data, update and handle responses from the view. I touched on this earlier but by separating this code into it&#8217;s own class you can have interfaces, subclasses, use unit testing on individual methods, and finally use the outline to jump to specific methods. Basically, everything that will help you grow as a developer as you make bullet proof applications.</p>
<p><strong>Best Practices:</strong> The controller includes whatever methods are necessary and a reference to the view. The methods/handlers that are required by the view will always be public, everything else is private or protected. All events handlers should be in the controller and then the controller modifies the model and/or changes the view. However the view NEVER directly accesses the model. Again, my events from the model are just straight Event classes, though you could always make custom events from your model, though it is probably a bit overkill. Notice especially that the model is set to private to protect it from the view and other components. If you wanted to allow accessors to specific data within the model you may want to add getters in the controller, though again this is highly discouraged.</p>
<p><strong>Refactoring Your Code To The Controller</strong><br />
Setting up your controller is simple, let&#8217;s start with a blank class.</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">unitedmindset</span>.<span style="color: #006600;">controllers</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SampleController<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SampleController<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now we just have to move the methods and change the functions that need to be available to the view to be public. Notice that the controller includes a model reference and listens for changes to the model and then updates the view as necessary.</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">unitedmindset</span>.<span style="color: #006600;">controllers</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">unitedmindset</span>.<span style="color: #006600;">models</span>.<span style="color: #006600;">SampleModel</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Alert</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">events</span>.<span style="color: #006600;">FlexEvent</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">FaultEvent</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ResultEvent</span>;<br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">http</span>.<span style="color: #006600;">HTTPService</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SampleController<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> view:UMBlogMVC;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _model:SampleModel;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SampleController<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _model = <span style="color: #000000; font-weight: bold;">new</span> SampleModel<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _model.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>SampleModel.<span style="color: #006600;">SEARCH_LIST_CHANGED</span>,_onSearchListChanged<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> application1_creationCompleteHandler<span style="color: #66cc66;">&#40;</span>event:FlexEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; runSearch<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _onSearchListChanged<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; view.<span style="color: #006600;">searchList</span>.<span style="color: #006600;">dataProvider</span> = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span> _model.<span style="color: #006600;">searchList</span> <span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> runSearch<span style="color: #66cc66;">&#40;</span>event:MouseEvent=<span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> service:HTTPService = <span style="color: #000000; font-weight: bold;">new</span> HTTPService<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; service.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ResultEvent.<span style="color: #006600;">RESULT</span>,_httpService_resultHandler<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; service.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>FaultEvent.<span style="color: #006600;">FAULT</span>,_httpService_faultHandler<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; service.<span style="color: #006600;">resultFormat</span> = <span style="color: #ff0000;">&quot;e4x&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; service.<span style="color: #0066CC;">url</span> = <span style="color: #ff0000;">&quot;http://www.someUrl.com/yourMethod&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; service.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>searchTerm:view.<span style="color: #006600;">searchInput</span>.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _httpService_resultHandler<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> service:HTTPService = event.<span style="color: #0066CC;">target</span> as HTTPService;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; service.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>ResultEvent.<span style="color: #006600;">RESULT</span>,_httpService_resultHandler<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; service.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>FaultEvent.<span style="color: #006600;">FAULT</span>,_httpService_faultHandler<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _model.<span style="color: #006600;">searchList</span> = event.<span style="color: #006600;">result</span> as <span style="color: #0066CC;">Array</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _httpService_faultHandler<span style="color: #66cc66;">&#40;</span>event:FaultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">var</span> service:HTTPService = event.<span style="color: #0066CC;">target</span> as HTTPService;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; service.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>ResultEvent.<span style="color: #006600;">RESULT</span>,_httpService_resultHandler<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; service.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>FaultEvent.<span style="color: #006600;">FAULT</span>,_httpService_faultHandler<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _model.<span style="color: #006600;">searchList</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;fault&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<blockquote><p>Some people will argue that the httpservice should be in the model rather than in the controller. This is a point of contention among some developers. I believe it should be in the controller (or in a simple command) because it is a piece of logic that requests the data from the server, not the data itself.</p></blockquote>
<p><strong>Your Simplified View</strong><br />
Finally we will refactor our view to just the view elements and making a reference to the controller instance in your declarations section (for Fx4).</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:Application xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> <br />
&nbsp; &nbsp; xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/halo&quot;</span> <br />
&nbsp; &nbsp; xmlns:controllers=<span style="color: #ff0000;">&quot;com.unitedmindset.controllers.*&quot;</span><br />
&nbsp; &nbsp; creationComplete=<span style="color: #ff0000;">&quot;controller.application1_creationCompleteHandler(event)&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>fx:Declarations<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>controllers:SampleController id=<span style="color: #ff0000;">&quot;controller&quot;</span> view=<span style="color: #ff0000;">&quot;{this}&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>fx:Declarations<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:VerticalLayout gap=<span style="color: #ff0000;">&quot;20&quot;</span> paddingBottom=<span style="color: #ff0000;">&quot;20&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;20&quot;</span> paddingRight=<span style="color: #ff0000;">&quot;20&quot;</span> paddingTop=<span style="color: #ff0000;">&quot;20&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:layout<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:HGroup <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>mx:Label <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Search Term&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:TextInput <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> id=<span style="color: #ff0000;">&quot;searchInput&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Do It!&quot;</span> click=<span style="color: #ff0000;">&quot;controller.runSearch(event)&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;/</span>s:HGroup<span style="color: #66cc66;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&lt;</span>s:<span style="color: #0066CC;">List</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> id=<span style="color: #ff0000;">&quot;searchList&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
<span style="color: #66cc66;">&lt;/</span>s:Application<span style="color: #66cc66;">&gt;</span></div></td></tr></tbody></table></div>
<p>Looking over this code you will notice that there is absolutely no logic in your view, keeping you view to only doing one thing, <em>looking good</em>. It is the controller instance that receives events from the view and the controller that houses all of your application&#8217;s logic.</p>
<p><strong>Wrapping It All Up</strong><br />
Hopefully this is illuminating and pushes you to do some code refactoring. What is also great about this style of programming is that it works right in with any of your favorite frameworks. If you are making an application and are wondering &#8220;Where does this code go?&#8221;, you just have to ask yourself &#8220;is this part of what is seen, the data, or logic within the application?&#8221;. This separation will also make it easier for when you are working with junior developers and they don&#8217;t know where to put code. I am sure you can already see the benefits to not having services in your view and being able to reuse controllers over multiple views, and the ability to continue abstracting your code to new levels.</p>
<p>Good luck, and happy coding!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://unitedmindset.com/jonbcampos/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://unitedmindset.com/jonbcampos/2009/08/18/flex-best-practices-models-views-and-controllers/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Flex Best Practices &#8211; Events</title>
		<link>http://unitedmindset.com/jonbcampos/2009/08/12/flex-best-practices-events/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=flex-best-practices-events</link>
		<comments>http://unitedmindset.com/jonbcampos/2009/08/12/flex-best-practices-events/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 14:39:41 +0000</pubDate>
		<dc:creator>Jonathan Campos</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[clone]]></category>
		<category><![CDATA[getters/setters]]></category>
		<category><![CDATA[naming]]></category>
		<category><![CDATA[overrides]]></category>
		<category><![CDATA[public properties]]></category>
		<category><![CDATA[Special Events]]></category>

		<guid isPermaLink="false">http://unitedmindset.com/jonbcampos/?p=675</guid>
		<description><![CDATA[I can&#8217;t stand seeing badly created code. ESPECIALLY code that works against best practices solely for the reason that the developer felt that using &#8220;best practices&#8221; would take too long or cause too many problems. The idea of best practices (in my opinion) are a set of rules to program by that don&#8217;t get in [...]]]></description>
			<content:encoded><![CDATA[<p>I can&#8217;t stand seeing badly created code. ESPECIALLY code that works against best practices solely for the reason that the developer felt that using &#8220;best practices&#8221; would take too long or cause too many problems.</p>
<p>The idea of best practices (in my opinion) are a set of rules to program by that don&#8217;t get in the way of programming while keeping a consistent, high-quality level of work while leaving minimal (to no) room for error based on coding practice not coding.</p>
<p>Basically, don&#8217;t keep coding around the problem and adding additional coding to fix the problem, just use best practices and more on.</p>
<p>Right now I am going to focus on events, arguably one of the most used set of classes in the Flex framework. For this set of examples I am going to assume that the developer knows that they have to AT LEAST extend the Event class for all events.<br />
<span id="more-675"></span><br />
So, some bad code&#8230;</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">unitedmindset</span>.<span style="color: #006600;">events</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> badevent <span style="color: #0066CC;">extends</span> Event<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> badevent<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span>, bubbles:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>, cancelable:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>, bubbles, cancelable<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Naming</strong></p>
<p>Wow, this code is bad right from the start. Notice the class name <strong>badevent</strong>. In Actionscript we follow the camel case naming convention. As such the name of this event should be <strong>badEvent</strong>. Notice that each word in the name of the class should start with an upper case (with the first word starting in lower case). Now classes are special, classes start with an upper case, so the FINAL name of our event should be <strong>BadEvent</strong>.</p>
<p>Next&#8230;</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">unitedmindset</span>.<span style="color: #006600;">events</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BadEvent <span style="color: #0066CC;">extends</span> Event<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> extraInfo1:<span style="color: #0066CC;">Object</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> extraInfo2:<span style="color: #0066CC;">Object</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> extraInfo3:<span style="color: #0066CC;">Object</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> BadEvent<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span>, bubbles:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>, cancelable:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>, bubbles, cancelable<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>Typing your variables</strong></p>
<p>I&#8217;m not EVEN going to start in on the naming of properties, but I will complain about the object typing. When the AS3 compiler sees an object it will create room for it in memory, but unlike a typed object it doesn&#8217;t know how much room to make, this is bad for memory. On top of that, the compiler can&#8217;t do type checking for you at compile time, so you have a greater probability of runtime exceptions in your application.</p>
<p>Quick update&#8230;</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">unitedmindset</span>.<span style="color: #006600;">events</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BadEvent <span style="color: #0066CC;">extends</span> Event<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> extraInfo1:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> extraInfo2:<span style="color: #0066CC;">int</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> extraInfo3:<span style="color: #0066CC;">XML</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> BadEvent<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span>, bubbles:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>, cancelable:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>, bubbles, cancelable<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now that little type change fixes our problem of type checking and memory performance. </p>
<blockquote><p>There are many other steps a developer must take to TRULY captialize on memory performance, this is just one drop in the bucket.</p></blockquote>
<p><strong>Protecting your properties</strong></p>
<p>However there is another problem with the properties on this event, they are exposed to change as it moves through the application. What I mean is: As the event is fired, it is very possible that there will be multiple listeners for that event. As the event hits on handler function the handler function may update the property. Now when the event gets to the next handler function the original data from the event has changed. This is unwanted and may lead to unexpected effects in your application.</p>
<p>Using getters we limit the properties from changing. We also will set the properties on the constructor so that the property can only be set when the event is created.</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">unitedmindset</span>.<span style="color: #006600;">events</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BadEvent <span style="color: #0066CC;">extends</span> Event<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _extraInfo1:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> extraInfo1<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> _extraInfo1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _extraInfo2:<span style="color: #0066CC;">int</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> extraInfo2<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> _extraInfo2;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _extraInfo3:<span style="color: #0066CC;">XML</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> extraInfo3<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">XML</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> _extraInfo3;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> BadEvent<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span>, extraInfo1:<span style="color: #0066CC;">String</span>, extraInfo2:<span style="color: #0066CC;">int</span>, extraInfo3:<span style="color: #0066CC;">XML</span>, bubbles:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>, cancelable:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>, bubbles, cancelable<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _extraInfo1 = extraInfo1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _extraInfo2 = extraInfo2;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _extraInfo3 = extraInfo3;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<blockquote><p>There may be a time you REALLY want to have the property able to change in an event as it moves through the application. I would highly discourage this as it works against best practices. As the event bubbles the changing logic in the event may be hard for future developers to follow or even find in the code.</p></blockquote>
<p>Please notice also that all private variables start with the underscore &#8220;_&#8221;. Using this makes it so that you don&#8217;t have to roll over each variable or look in the outline to see if it is private or not.</p>
<p><strong>Clone function</strong><br />
As an event bubbles through the application, or if you need to make a duplicate of the event, you call the <strong>clone</strong> function. However, if we don&#8217;t state the the clone function will return your newly created event type it will, by default, return just a normal event. This is highly undesirable for your application. So next we override the clone function.</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> clone<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:Event<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> BadEvent<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>, extraInfo1, extraInfo2, extraInfo3, bubbles, cancelable<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>You will see here that we have created a new event instance and passed the variables available to this event into the new instance. and returned that instance. Very simple bit of code that will protect your program.</p>
<p><strong>Event types</strong><br />
Now we need to create constants to describe what action this event is representing. This is very simple and very helpful. As event listeners are ultimately looking for a string match you COULD type the string right into the listener&#8230;</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">component.addEventListener(&quot;click&quot;,_handler)</div></td></tr></tbody></table></div>
<p>If you have a developer like me that can&#8217;t spell or adds the wrong tense, then I may accidentally do this&#8230;</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">component.addEventListener(&quot;clicked&quot;,_handler)</div></td></tr></tbody></table></div>
<p>Now we spend all day looking for why the handler is never being called. Again, this is solved with some constants.</p>
<div class="codecolorer-container actionscript dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br /></div></td><td><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.<span style="color: #006600;">unitedmindset</span>.<span style="color: #006600;">events</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BadEvent <span style="color: #0066CC;">extends</span> Event<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const CLICK_BUTTON_1:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;clickButton1&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const CLICK_BUTTON_2:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;clickButton2&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> const CLICK_BUTTON_3:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;clickButton3&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _extraInfo1:<span style="color: #0066CC;">String</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> extraInfo1<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> _extraInfo1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _extraInfo2:<span style="color: #0066CC;">int</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> extraInfo2<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> _extraInfo2;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _extraInfo3:<span style="color: #0066CC;">XML</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> extraInfo3<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">XML</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> _extraInfo3;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> BadEvent<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>:<span style="color: #0066CC;">String</span>, extraInfo1:<span style="color: #0066CC;">String</span>, extraInfo2:<span style="color: #0066CC;">int</span>, extraInfo3:<span style="color: #0066CC;">XML</span>, bubbles:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>, cancelable:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>, bubbles, cancelable<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _extraInfo1 = extraInfo1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _extraInfo2 = extraInfo2;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _extraInfo3 = extraInfo3;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; override <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> clone<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:Event<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> BadEvent<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">type</span>, extraInfo1, extraInfo2, extraInfo3, bubbles, cancelable<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now with the constants the intellisense will give me some assistance and I get the following code for adding my event listener. No possibility for spelling and grammar mistakes here.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">component.addEventListener(BadEvent.CLICK_BUTTON_1,_handler)</div></td></tr></tbody></table></div>
<p>Also notice that the constants we difine is all in upper case with underscores between the individual words. This is another best practice and camel case naming practice. Again, this just quickly alerts other users that this is a constant.</p>
<p><strong>ASDoc</strong><br />
Finally, before we lock up any class we add ASDocs for future developers. Below is the FINAL class.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">package com.unitedmindset.events<br />
{<br />
&nbsp; &nbsp; import flash.events.Event;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp;* This event is fired when a user clicks on one of three buttons. <br />
&nbsp; &nbsp; &nbsp;* @author Administrator<br />
&nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp;*/ <br />
&nbsp; &nbsp; public class GoodEvent extends Event<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; public static const CLICK_BUTTON_1:String = &quot;clickButton1&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; public static const CLICK_BUTTON_2:String = &quot;clickButton2&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; public static const CLICK_BUTTON_3:String = &quot;clickButton3&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; private var _extraInfo1:String;<br />
&nbsp; &nbsp; &nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Button label. <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @return <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/ &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; public function get extraInfo1():String<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return _extraInfo1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; private var _extraInfo2:int;<br />
&nbsp; &nbsp; &nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Button position. <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @return <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/ &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; public function get extraInfo2():int<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return _extraInfo2;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; private var _extraInfo3:XML;<br />
&nbsp; &nbsp; &nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* XML button loads. <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @return <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/ &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; public function get extraInfo3():XML<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return _extraInfo3;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Constructor <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param type<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param extraInfo1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param extraInfo2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param extraInfo3<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param bubbles<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param cancelable<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/ &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; public function GoodEvent(type:String, extraInfo1:String, extraInfo2:int, extraInfo3:XML, bubbles:Boolean=false, cancelable:Boolean=false)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; super(type, bubbles, cancelable);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _extraInfo1 = extraInfo1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _extraInfo2 = extraInfo2;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _extraInfo3 = extraInfo3;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Returns new GoodEvent. <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @return <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/ &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; override public function clone():Event<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return new GoodEvent(type, extraInfo1, extraInfo2, extraInfo3, bubbles, cancelable);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; }<br />
}</div></td></tr></tbody></table></div>
<p><strong>Conclusion</strong><br />
Some people would ask why write a blog post that is so simple. I wrote this one because all the bad examples presented I have witnessed in life code over the last few weeks. I am sure that is both surprising and not surprising.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://unitedmindset.com/jonbcampos/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://unitedmindset.com/jonbcampos/2009/08/12/flex-best-practices-events/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
