<?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>zedia flash blog &#187; function</title>
	<atom:link href="http://www.zedia.net/tag/function/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zedia.net</link>
	<description>Flash, ActionScript, SEO and everything in between</description>
	<lastBuildDate>Wed, 21 Jul 2010 17:07:49 +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>How to reuse event functions</title>
		<link>http://www.zedia.net/2009/how-to-reuse-event-functions/</link>
		<comments>http://www.zedia.net/2009/how-to-reuse-event-functions/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 18:36:53 +0000</pubDate>
		<dc:creator>zedia.net</dc:creator>
				<category><![CDATA[ActionScript 3]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://www.zedia.net/?p=311</guid>
		<description><![CDATA[This is just a quick tip I picked up while working with a teamate. I often came across the case that I would have to make a function exactly the same as the function that was called from an event listener because the function called from the listener would have an event as argument but [...]]]></description>
			<content:encoded><![CDATA[<p>This is just a quick tip I picked up while working with a teamate.</p>
<p>I often came across the case that I would have to make a function exactly the same as the function that was called from an event listener because the function called from the listener would have an event as argument but the same function that I wanted to call but not from an event didn&#8217;t.</p>
<p>I had found multiple ways around that problem; I would make another function that both previous function would call or I would create only the listener function and when I wanted to call it from elswhere I would pass it an empty event that I would create just for it. Both these solution appeared unelegant to me.</p>
<p>That&#8217;s when I saw this in my teamate code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// let say your listener is this</span>
myButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, _activateElement, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">//your function looks like this</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _activateElement<span style="color: #66cc66;">&#40;</span>event:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
  <span style="color: #808080; font-style: italic;">//do something that doesn't require the event</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//so from anywhere you can just call the same function like this</span>
_activateElement<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>By simply giving <strong>a default value of null to the argument</strong>, you can now reuse this function both in the context of an event listener and anywhere else.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.zedia.net%2F2009%2Fhow-to-reuse-event-functions%2F&amp;layout=standard&amp;show-faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:550px; height:70px;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.zedia.net/2009/how-to-reuse-event-functions/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
