<?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>Kalen Gibbons &#187; overloaded</title>
	<atom:link href="http://www.kalengibbons.com/blog/index.php/tag/overloaded/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kalengibbons.com/blog</link>
	<description>The Dead Tree Blog</description>
	<lastBuildDate>Wed, 10 Mar 2010 07:28:09 +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>Dynamic Parameters in ActionScript 3.0</title>
		<link>http://www.kalengibbons.com/blog/index.php/2007/07/dynamic-parameters-in-actionscript-30/</link>
		<comments>http://www.kalengibbons.com/blog/index.php/2007/07/dynamic-parameters-in-actionscript-30/#comments</comments>
		<pubDate>Wed, 18 Jul 2007 21:34:40 +0000</pubDate>
		<dc:creator>Kalen Gibbons</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[arguments]]></category>
		<category><![CDATA[overloaded]]></category>
		<category><![CDATA[parameters]]></category>

		<guid isPermaLink="false">http://www.kalengibbons.com/blog2/?p=11</guid>
		<description><![CDATA[Note: This post has been renamed, because its original title &#8220;Optional Parameters in ActionScript 3.0&#8243; was a bit misleading. For more information on optional parameters please visit the following livedocs page. You&#8217;ve gotta love &#8230;rest! Since ActionScript 3.0 doesn&#8217;t support overloaded constructors (booo), &#8230;rest is a pseudo way of overloading your methods. &#8230;rest is an [...]]]></description>
			<content:encoded><![CDATA[<p class="notice">Note: This post has been renamed, because its original title &#8220;Optional Parameters in ActionScript 3.0&#8243; was a bit misleading.  For more information on optional parameters please visit the following <a href="http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&amp;file=03_Language_and_Syntax_160_19.html">livedocs page</a>.</p>
<p>You&#8217;ve gotta love &#8230;rest!  Since ActionScript 3.0 doesn&#8217;t support overloaded constructors (booo), &#8230;rest is a pseudo way of overloading your methods.  &#8230;rest is an argument parameter that allows you to pass in multiple arguments of various lengths and datatypes.  So, for example, if you have a function that converts degrees Fahrenheit into degrees Celsius, you may need to call this function with various parameters:</p>
<div class="code"><span class="asComment">//function to convert Fahrenheit to Celsius</span></p>
<p><span class="asReserved">private</span> <span class="asFunction">function</span> toCelsius(_Fahrenheit:Object, &#8230;rest):Number{</p>
<div class="indent"><span class="asVar">var</span> _Celsius:Number = (5/9)*(_Fahrenheit.degrees-32);<br />
<span class="asReserved">return</span> _Celsius</div>
<p>}</p>
<p>&nbsp;</p>
<p><span class="asComment">//passes single parameter, Fahrenheit object</span><br />
Alert.show(&#8220;<span class="asString">Degress Celcius: &#8220;</span> + toCelsius(degreeFahrenheit));</p>
<p>&nbsp;</p>
<p><span class="asComment">//passes two parameters, Fahrenheit object and length </span><br />
degFarenheit = <span class="asReserved">new</span> DataGridColumn();<br />
degFarenheit.labelFunction = toCelsius <span class="asReserved">as</span> Function;</div>
<p>By using &#8230;rest, the toCelsius function will ignore any additional parameters that might get passed in and that would normal throw an error.  What&#8217;s even better, is that you can name your &#8230;(rest) parameter and ActionScript will store a reference to all the parameters passed in as an array.  This is what really allows you to create one method signature that can act like overloaded functions.  For example:</p>
<div class="code"><span class="asComment">//you can name your optional parameter and reference it accordingly</span></p>
<p><span class="asReserved">private</span> <span class="asFunction">function</span> overloadTest(&#8230;myArguments):String{</p>
<div class="indent"><span class="asReserved">switch</span> (myArguments.length){</p>
<div class="indent"><span class="asReserved">case</span> 0:</p>
<div class="indent">&#8230; code A &#8230;<br />
<span class="asReserved">return</span> <span class="asString">&#8220;signature A&#8221;</span>;</div>
<p><span class="asReserved">case</span> 1:</p>
<div class="indent">&#8230; code B &#8230;<br />
<span class="asReserved">return</span> <span class="asString">&#8220;signature B&#8221;</span>;</div>
<p><span class="asReserved">case</span> 2:</p>
<div class="indent">&#8230; code C &#8230;<br />
<span class="asReserved">return</span> <span class="asString">&#8220;signature C&#8221;</span>;</div>
<p><span class="asReserved">default</span>:</p>
<div class="indent">&#8230; code D &#8230;<br />
<span class="asReserved">return</span> <span class="asString">&#8220;signature D&#8221;</span>;</div>
</div>
<p>}</p></div>
<p>}</p></div>
<p>And although this doesn&#8217;t make up for ActionScript&#8217;s lack of overloading support, it does make life a little simpler and more flexible.   I am a big fan of &#8230;rest!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kalengibbons.com/blog/index.php/2007/07/dynamic-parameters-in-actionscript-30/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
