<?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>Calm in the Chaos &#187; combobox</title>
	<atom:link href="http://blog.wrench.com.au/tag/combobox/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.wrench.com.au</link>
	<description>Flash, Air, Mobile &#38; Technology tidbits</description>
	<lastBuildDate>Fri, 22 Feb 2013 16:38:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>Passing parameters to a Flex eventListener &#8211; use a Dictionary!</title>
		<link>http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/</link>
		<comments>http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 14:29:49 +0000</pubDate>
		<dc:creator>Jason Langdon</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[addEventListener]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[combobox]]></category>
		<category><![CDATA[Dictionary]]></category>
		<category><![CDATA[eventListener]]></category>
		<category><![CDATA[parametr]]></category>

		<guid isPermaLink="false">http://blog.wrench.com.au/?p=202</guid>
		<description><![CDATA[Firstly, Happy New Year! Hope your &#8217;09 is off to a flyer! Secondly, sorry about the rather mundane heading &#8211; couldn&#8217;t really think of what to call this post. I&#8217;ve been typing all sorts of things into Google trying to<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
			<content:encoded><![CDATA[<p>Firstly, Happy New Year! Hope your &#8217;09 is off to a flyer!</p>
<p>Secondly, sorry about the rather mundane heading &#8211; couldn&#8217;t really think of what to call this post. I&#8217;ve been typing all sorts of things into Google trying to find a solution to what I&#8217;ll describe below.</p>
<p>I&#8217;m continuing the project I started in early December and having some very interesting battles with AS3 and the Flex framework. I&#8217;d like to document one of those battles today.</p>
<p>What I wanted to do was send parameters along with an event so that the event listener had access to them. Now I&#8217;m fully aware of how to do that when I&#8217;m in charge of dispatching the event, but was (and still am) at a loss as to how to add them in the following instance:</p>
<pre class="code">
myComboBox.addEventListener(Event.CHANGE, eventListener);
</pre>
<p>This call to addEventListener occurs where the variables I want to pass get defined.</p>
<p>Here&#8217;s the code that I attempted to use (without luck) to get the parameters passed along with the event:</p>
<pre class="code">
myComboBox.addEventListener(PodEvent.CHANGE, eventListener);
var myEvent:PodEvent = new PodEvent(PodEvent.CHANGE);
myEvent.displayTriggerValue = displayTriggerValue;
myEvent.formItem = triggerDisplay;
myComboBox.dispatchEvent(myEvent);
</pre>
<p>I could get the displayTriggerListener to run when the combobox changed, but the variables that I added to myEvent wouldn&#8217;t make it in there (further to that I was having type coercion difficulties, but that&#8217;s another story I think). The initial dispatchEvent was also allowing the eventListener to get the parameters, but obviously the idea is to have them passed along with every PodEvent.CHANGE event.</p>
<p>Now initially I got around this using closures (a new term to me). I understand the issues of using anonymous functions (ie. garbage collection issues) so searched some more for answers. I found nada.</p>
<p>So after a nights rest and a few more hours wrestling with it today, I&#8217;ve come up with the following solution that I&#8217;m rather chuffed about. I use a Dictionary to store a reference to the component and in turn create an object associated with that Dictionary element to store the parameters I want to pass into the eventListener function. Perhaps some code will illustrate what the hell I just typed (for me and you both <img src='http://blog.wrench.com.au/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<pre class="code">
myParamDictionary[myComboBox] = {param1: value1, param2: value2};
</pre>
<p>The myParamDictionary is a private var in the class so is accessible within the eventListener</p>
<pre class="code">
private function eventListener(e:Event):void {
	var _local:* = myParamDictionary[e.target]
	// rest of the implementation here. You can access the previously set parameters by _local.param1, _local.param2...
}
</pre>
<p>And to my utter delight (and surprise) it works!</p>
<p>The only downside is there&#8217;s no type checking on the parameters, which is what I originally wanted to use a custom event for.</p>
<p>If you&#8217;ve got a suggestion for my initial problem or a critique for my end solution please don&#8217;t be shy and post them!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
