<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Passing parameters to a Flex eventListener - use a Dictionary!</title>
	<atom:link href="http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/</link>
	<description>Flash, Flex and Technology</description>
	<pubDate>Wed, 10 Mar 2010 03:47:31 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Jason Langdon</title>
		<link>http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/#comment-6523</link>
		<dc:creator>Jason Langdon</dc:creator>
		<pubDate>Tue, 26 May 2009 10:12:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wrench.com.au/?p=202#comment-6523</guid>
		<description>@madhu - I think it's now fairly evident (after 6 months of working in Flex) that extending the combobox and the event that it broadcasts are now the way to go. The dictionary approach that I suggested did work, but was a bit hacky and probably not something that I'd use going forward.

Thanks for stopping by and adding your 2 cents.</description>
		<content:encoded><![CDATA[<p>@madhu - I think it&#8217;s now fairly evident (after 6 months of working in Flex) that extending the combobox and the event that it broadcasts are now the way to go. The dictionary approach that I suggested did work, but was a bit hacky and probably not something that I&#8217;d use going forward.</p>
<p>Thanks for stopping by and adding your 2 cents.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhu</title>
		<link>http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/#comment-6522</link>
		<dc:creator>madhu</dc:creator>
		<pubDate>Tue, 26 May 2009 08:20:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wrench.com.au/?p=202#comment-6522</guid>
		<description>I do not know why we need dictionary object, I was able to access public properties of the event by type casting the event.

I used clone to get my custom properties also.

	import flash.events.Event;

	public class AlignControlEvent extends Event
	{
		public var ControlName:String;
		public var ControlType:String;
		
		public static const ALIGN_CONTROL_EVENT:String = "alignControlEvent";
		public function AlignControlEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
		{
			super(type, bubbles, cancelable);
		}
		public override function clone():Event
		{
			var objAlignControlEvent:AlignControlEvent;
			objAlignControlEvent = new AlignControlEvent(this.type, this.bubbles, this.cancelable);
			objAlignControlEvent.ControlName = this.ControlName;
			objAlignControlEvent.ControlType = this.ControlType;
			
			return objAlignControlEvent; 
		}
		
	}



while dispatching
var objAlignControlEvent:AlignControlEvent = new AlignControlEvent(AlignControlEvent.ALIGN_CONTROL_EVENT);
objAlignControlEvent.ControlType = this._type;
objAlignControlEvent.ControlName = this._name;
dispatchEvent(objAlignControlEvent);



And in handling i read them as
var objA:AlignControlEvent;
objA = (e as AlignControlEvent);
Alert.show("[align control] [name]"  objA.ControlName   " [type]"  objA.ControlType) ;</description>
		<content:encoded><![CDATA[<p>I do not know why we need dictionary object, I was able to access public properties of the event by type casting the event.</p>
<p>I used clone to get my custom properties also.</p>
<p>	import flash.events.Event;</p>
<p>	public class AlignControlEvent extends Event<br />
	{<br />
		public var ControlName:String;<br />
		public var ControlType:String;</p>
<p>		public static const ALIGN_CONTROL_EVENT:String = &#8220;alignControlEvent&#8221;;<br />
		public function AlignControlEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)<br />
		{<br />
			super(type, bubbles, cancelable);<br />
		}<br />
		public override function clone():Event<br />
		{<br />
			var objAlignControlEvent:AlignControlEvent;<br />
			objAlignControlEvent = new AlignControlEvent(this.type, this.bubbles, this.cancelable);<br />
			objAlignControlEvent.ControlName = this.ControlName;<br />
			objAlignControlEvent.ControlType = this.ControlType;</p>
<p>			return objAlignControlEvent;<br />
		}</p>
<p>	}</p>
<p>while dispatching<br />
var objAlignControlEvent:AlignControlEvent = new AlignControlEvent(AlignControlEvent.ALIGN_CONTROL_EVENT);<br />
objAlignControlEvent.ControlType = this._type;<br />
objAlignControlEvent.ControlName = this._name;<br />
dispatchEvent(objAlignControlEvent);</p>
<p>And in handling i read them as<br />
var objA:AlignControlEvent;<br />
objA = (e as AlignControlEvent);<br />
Alert.show(&#8221;[align control] [name]&#8221;  objA.ControlName   &#8221; [type]&#8221;  objA.ControlType) ;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PSmith</title>
		<link>http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/#comment-6503</link>
		<dc:creator>PSmith</dc:creator>
		<pubDate>Tue, 03 Feb 2009 15:43:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wrench.com.au/?p=202#comment-6503</guid>
		<description>I am a newbie and I think that I am attempting to do the same thing.  I have a parent module that needs to trigger an event (button pressed on ButtonBar).  I need a component module to see the event and be able to tell which button was pressed and do something based upon which button was pressed.  In my parent module, I have:

	[Event(name="navButtonClicked", type="mx.events.ItemClickEvent")]


and a function:
public function navButtonsEvent():void {
	dispatchEvent(new Event("navButtonClicked"));
}

and the buttonbar:



In my component module I have (not complete, just testing):
public function navButtons(event:ItemClickEvent):void {
	var whichButton:int = event.index;
	switch(whichButton) {
		case 0:
			focusManager.setFocus(discrepancyItems[0]);
			break;
		case 1:
			focusManager.setFocus(discrepancyItems[0]);
			break;					
		case 2:
			focusManager.setFocus(discrepancyItems[0]);
			break;					
		case 3:
			focusManager.setFocus(discrepancyItems[discrepancyCount]);
			break;
	}
}

What do I need to add where for the component module to see the button click?</description>
		<content:encoded><![CDATA[<p>I am a newbie and I think that I am attempting to do the same thing.  I have a parent module that needs to trigger an event (button pressed on ButtonBar).  I need a component module to see the event and be able to tell which button was pressed and do something based upon which button was pressed.  In my parent module, I have:</p>
<p>	[Event(name="navButtonClicked", type="mx.events.ItemClickEvent")]</p>
<p>and a function:<br />
public function navButtonsEvent():void {<br />
	dispatchEvent(new Event(&#8221;navButtonClicked&#8221;));<br />
}</p>
<p>and the buttonbar:</p>
<p>In my component module I have (not complete, just testing):<br />
public function navButtons(event:ItemClickEvent):void {<br />
	var whichButton:int = event.index;<br />
	switch(whichButton) {<br />
		case 0:<br />
			focusManager.setFocus(discrepancyItems[0]);<br />
			break;<br />
		case 1:<br />
			focusManager.setFocus(discrepancyItems[0]);<br />
			break;<br />
		case 2:<br />
			focusManager.setFocus(discrepancyItems[0]);<br />
			break;<br />
		case 3:<br />
			focusManager.setFocus(discrepancyItems[discrepancyCount]);<br />
			break;<br />
	}<br />
}</p>
<p>What do I need to add where for the component module to see the button click?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Langdon</title>
		<link>http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/#comment-6484</link>
		<dc:creator>Jason Langdon</dc:creator>
		<pubDate>Sun, 11 Jan 2009 17:37:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wrench.com.au/?p=202#comment-6484</guid>
		<description>@Erid - Thanks for following up. However, what you've suggested doesn't really help me in this instance (and yes, I'm fully aware of using event.target to get access to all sorts of information about the object that broadcast the event). I need to know what item to show and hide (which is totally separate from the combobox) when the combobox is set to the designated trigger item. This information isn't passed along with the event.

I couldn't retrieve the code posted, and I'm doing this part of the code in actionscript so MXML isn't really relevant.

For future reference, code placed within a "code" tag should appear ok in the comments.</description>
		<content:encoded><![CDATA[<p>@Erid - Thanks for following up. However, what you&#8217;ve suggested doesn&#8217;t really help me in this instance (and yes, I&#8217;m fully aware of using event.target to get access to all sorts of information about the object that broadcast the event). I need to know what item to show and hide (which is totally separate from the combobox) when the combobox is set to the designated trigger item. This information isn&#8217;t passed along with the event.</p>
<p>I couldn&#8217;t retrieve the code posted, and I&#8217;m doing this part of the code in actionscript so MXML isn&#8217;t really relevant.</p>
<p>For future reference, code placed within a &#8220;code&#8221; tag should appear ok in the comments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Cancil</title>
		<link>http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/#comment-6483</link>
		<dc:creator>Eric Cancil</dc:creator>
		<pubDate>Sun, 11 Jan 2009 16:09:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wrench.com.au/?p=202#comment-6483</guid>
		<description>sorry my mxml markup wasnt shown - and I can't edit it...you might be able to fix it</description>
		<content:encoded><![CDATA[<p>sorry my mxml markup wasnt shown - and I can&#8217;t edit it&#8230;you might be able to fix it</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Cancil</title>
		<link>http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/#comment-6482</link>
		<dc:creator>Eric Cancil</dc:creator>
		<pubDate>Sun, 11 Jan 2009 16:08:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wrench.com.au/?p=202#comment-6482</guid>
		<description>@ jason
This can be done easily through an event listener just by saying
var combo:ComboBox(event.target as ComboBox);
//then
combo.selectedItem
combo.selectedIndex
etc etc....


you can even do something like this



or since event gets passed in

</description>
		<content:encoded><![CDATA[<p>@ jason<br />
This can be done easily through an event listener just by saying<br />
var combo:ComboBox(event.target as ComboBox);<br />
//then<br />
combo.selectedItem<br />
combo.selectedIndex<br />
etc etc&#8230;.</p>
<p>you can even do something like this</p>
<p>or since event gets passed in</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Langdon</title>
		<link>http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/#comment-6480</link>
		<dc:creator>Jason Langdon</dc:creator>
		<pubDate>Sun, 11 Jan 2009 10:56:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wrench.com.au/?p=202#comment-6480</guid>
		<description>Thanks for the comments guys.

@Eric - The reason I NEED to do this is I'm generating a form element based on the currently selected item in a combobox. Now that formitem is intelligent in that it knows what combobox and the selected item of that combobox that will trigger it's display. But this information needs to make it into the eventListener so it can determine whether the correct item is selected. Hopefully that clarifies why I need to send the parameters along with the event. Have you got any suggestions for other ways of achieving the same thing?

As for tight coupling, well the combobx is generated within the same class as the privately declared dictionary - which too me is perfectly fine. Pragmatism has to take charge at some stage, and I see nothing wrong with declaring a private variable in a class that will then be referenced by a combobox created in that same class. That's more like logical coupling to me.

I am setting up my Dictionary with true as it's constructor parameter.

@Chris and Tink - I did add a clone method, still no cigar. And I realised that my initial dispatch was the only thing that was carrying the parameters along to the eventListener (hence this post).

To me extending a component to pass parameters along seems like overkill in this situation. But I'm glad to know that seems to be the approach required for future issues I may run into.</description>
		<content:encoded><![CDATA[<p>Thanks for the comments guys.</p>
<p>@Eric - The reason I NEED to do this is I&#8217;m generating a form element based on the currently selected item in a combobox. Now that formitem is intelligent in that it knows what combobox and the selected item of that combobox that will trigger it&#8217;s display. But this information needs to make it into the eventListener so it can determine whether the correct item is selected. Hopefully that clarifies why I need to send the parameters along with the event. Have you got any suggestions for other ways of achieving the same thing?</p>
<p>As for tight coupling, well the combobx is generated within the same class as the privately declared dictionary - which too me is perfectly fine. Pragmatism has to take charge at some stage, and I see nothing wrong with declaring a private variable in a class that will then be referenced by a combobox created in that same class. That&#8217;s more like logical coupling to me.</p>
<p>I am setting up my Dictionary with true as it&#8217;s constructor parameter.</p>
<p>@Chris and Tink - I did add a clone method, still no cigar. And I realised that my initial dispatch was the only thing that was carrying the parameters along to the eventListener (hence this post).</p>
<p>To me extending a component to pass parameters along seems like overkill in this situation. But I&#8217;m glad to know that seems to be the approach required for future issues I may run into.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tink</title>
		<link>http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/#comment-6479</link>
		<dc:creator>Tink</dc:creator>
		<pubDate>Sat, 10 Jan 2009 22:43:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wrench.com.au/?p=202#comment-6479</guid>
		<description>@ Chris

Juts because a custom event is created and dispatched immediately, it doesn't have any effect on the event that the ComboBox will despatch when its selectedIndex is changde. When this happens, an Event.CHANGE is dispatched.

If you wanted to dispatch a custom event you would have to do what Eric stated and extend ComboBox, and dispatch you own event where ever the Event.CHANGE was dispatched.

Thats said, like Eric also mentioned this isn't a great solution, although I guess we don't fully know the reasons behind it.</description>
		<content:encoded><![CDATA[<p>@ Chris</p>
<p>Juts because a custom event is created and dispatched immediately, it doesn&#8217;t have any effect on the event that the ComboBox will despatch when its selectedIndex is changde. When this happens, an Event.CHANGE is dispatched.</p>
<p>If you wanted to dispatch a custom event you would have to do what Eric stated and extend ComboBox, and dispatch you own event where ever the Event.CHANGE was dispatched.</p>
<p>Thats said, like Eric also mentioned this isn&#8217;t a great solution, although I guess we don&#8217;t fully know the reasons behind it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/#comment-6478</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Sat, 10 Jan 2009 17:37:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wrench.com.au/?p=202#comment-6478</guid>
		<description>I dont really see why your original idea of creating a custom event didnt work, you did add a clone method to your event class right? Because if you didm surely the event would still have had the properties you assigned it.</description>
		<content:encoded><![CDATA[<p>I dont really see why your original idea of creating a custom event didnt work, you did add a clone method to your event class right? Because if you didm surely the event would still have had the properties you assigned it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Cancil</title>
		<link>http://blog.wrench.com.au/2009/01/09/passing-parameters-to-a-flex-eventlistener-use-a-dictionary/#comment-6477</link>
		<dc:creator>Eric Cancil</dc:creator>
		<pubDate>Fri, 09 Jan 2009 16:40:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wrench.com.au/?p=202#comment-6477</guid>
		<description>I can't see a LOT of reasons why you'd want to do this.  But if you were going to do it - it would probably be smarter to extend combobox so you could have more control over events that were being dispatched and whatnot instead of so tightly coupling a random dictionary in a class to a combobox... Not only does this tightly couple things, but it also creates a random dictionary in memory that is just nt necessary.  Also, if you are using the dictionary, make sure to set it to use weak references - or else it will hold onto that combobox in memory and it will never be garbage collected.

Eric</description>
		<content:encoded><![CDATA[<p>I can&#8217;t see a LOT of reasons why you&#8217;d want to do this.  But if you were going to do it - it would probably be smarter to extend combobox so you could have more control over events that were being dispatched and whatnot instead of so tightly coupling a random dictionary in a class to a combobox&#8230; Not only does this tightly couple things, but it also creates a random dictionary in memory that is just nt necessary.  Also, if you are using the dictionary, make sure to set it to use weak references - or else it will hold onto that combobox in memory and it will never be garbage collected.</p>
<p>Eric</p>
]]></content:encoded>
	</item>
</channel>
</rss>
