<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.5" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: AsBroadcaster vs. BroadcasterMX vs. EventDispatcher</title>
	<link>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm</link>
	<description>Just Blog</description>
	<pubDate>Fri, 30 Jul 2010 09:24:25 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>

	<item>
		<title>by: jgraup</title>
		<link>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-3012</link>
		<pubDate>Sun, 03 Jun 2007 08:39:29 +0000</pubDate>
		<guid>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-3012</guid>
					<description>easy class implementation of eventDispatcher:


class myClass
{
	private static var EventDispatcherDependancy = mx.events.EventDispatcher.initialize ( myClass.prototype );
	public var addEventListener:Function;
	public var removeEventListener:Function;
	public var dispatchEvent:Function;
	public var dispatchQueue:Function;

	public function myClass (){}
}</description>
		<content:encoded><![CDATA[<p>easy class implementation of eventDispatcher:</p>
<p>class myClass<br />
{<br />
	private static var EventDispatcherDependancy = mx.events.EventDispatcher.initialize ( myClass.prototype );<br />
	public var addEventListener:Function;<br />
	public var removeEventListener:Function;<br />
	public var dispatchEvent:Function;<br />
	public var dispatchQueue:Function;</p>
<p>	public function myClass (){}<br />
}
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: jgraup</title>
		<link>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-3002</link>
		<pubDate>Sun, 03 Jun 2007 04:01:49 +0000</pubDate>
		<guid>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-3002</guid>
					<description>Muzak made a screencast of using Event Dispatcher and the Delegate as a encapsulation, OOP and best practices example.

The Flash app you seen in the video is part of a larger app that spits out a complete ARP application and actually writes .as files to disk.

http://muzakdeezign.com/flashcoders/create_component/MyButton.html</description>
		<content:encoded><![CDATA[<p>Muzak made a screencast of using Event Dispatcher and the Delegate as a encapsulation, OOP and best practices example.</p>
<p>The Flash app you seen in the video is part of a larger app that spits out a complete ARP application and actually writes .as files to disk.</p>
<p><a href="http://muzakdeezign.com/flashcoders/create_component/MyButton.html" rel="nofollow">http://muzakdeezign.com/flashcoders/create_component/MyButton.html</a>
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: jgraup</title>
		<link>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-2997</link>
		<pubDate>Sun, 03 Jun 2007 02:48:06 +0000</pubDate>
		<guid>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-2997</guid>
					<description>Great Explanation by Kirupa
http://www.kirupa.com/developer/actionscript/eventdispatcher.htm</description>
		<content:encoded><![CDATA[<p>Great Explanation by Kirupa<br />
<a href="http://www.kirupa.com/developer/actionscript/eventdispatcher.htm" rel="nofollow">http://www.kirupa.com/developer/actionscript/eventdispatcher.htm</a>
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: jgraup</title>
		<link>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-1352</link>
		<pubDate>Mon, 02 Apr 2007 15:46:26 +0000</pubDate>
		<guid>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-1352</guid>
					<description>How costly is dispatching events using the AS3 event model ?
http://lab.polygonal.de/2007/02/26/how-costly-is-dispatching-events-using-the-as3-event-model/

"By the way, in AS2 the fastest way to dispatch events is using the AsBroadcaster class, and the more listeners you add, the faster it gets compared to direct method invocation."

Well there ya go!</description>
		<content:encoded><![CDATA[<p>How costly is dispatching events using the AS3 event model ?<br />
<a href="http://lab.polygonal.de/2007/02/26/how-costly-is-dispatching-events-using-the-as3-event-model/" rel="nofollow">http://lab.polygonal.de/2007/02/26/how-costly-is-dispatching-events-using-the-as3-event-model/</a></p>
<p>&#8220;By the way, in AS2 the fastest way to dispatch events is using the AsBroadcaster class, and the more listeners you add, the faster it gets compared to direct method invocation.&#8221;</p>
<p>Well there ya go!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: jgraup</title>
		<link>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-1302</link>
		<pubDate>Fri, 30 Mar 2007 23:29:25 +0000</pubDate>
		<guid>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-1302</guid>
					<description>On a random note, using the Delegate as a proxy method shown above gives no reference to the subscriber. If you want to use the Delegate in that way, read up on jgDelegate2.as which includes a reference of itself in the function. The only way to unsubscribe is to use scope reference that the delegate has access to when it's called.

The alternate is to store a variable of the function and pass that as the listener.</description>
		<content:encoded><![CDATA[<p>On a random note, using the Delegate as a proxy method shown above gives no reference to the subscriber. If you want to use the Delegate in that way, read up on jgDelegate2.as which includes a reference of itself in the function. The only way to unsubscribe is to use scope reference that the delegate has access to when it&#8217;s called.</p>
<p>The alternate is to store a variable of the function and pass that as the listener.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: jgraup</title>
		<link>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-1300</link>
		<pubDate>Fri, 30 Mar 2007 19:11:27 +0000</pubDate>
		<guid>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-1300</guid>
					<description>&lt;p&gt;I tend to use EventDispatcher all the time because of it's ability to subscribe/unsubscribe to single events and the way you can proxy those events with a Delegate.&lt;/p&gt;
&lt;p&gt;// typical&lt;br /&gt;
obj.addEventListener ( 'someEvent', this );&lt;/p&gt;
&lt;p&gt;// scoped and proxied event&lt;br /&gt;
obj.addEventListener ( 'someEvent', mx.utils.Delegate.create ( this, myEventfunction );&lt;/p&gt;
&lt;p&gt;The advantage of the later is that you can choose the scope and an alternately named function. The overhead occurs when it passes an object with all the information, not limited to the target and type sent by obj, but any property you want to add. &lt;/p&gt;
&lt;p&gt;I use this method in my UIEventMovieClip class:&lt;br /&gt;
private function newEvent ( type, eventObj:Object ):Void&lt;br /&gt;
{&lt;br /&gt;
	// check for optional passed prams&lt;br /&gt;
	var eventObj = ( eventObj != undefined ) ? eventObj : new Object ();&lt;br /&gt;
	// set event type&lt;br /&gt;
	eventObj.type = type;&lt;br /&gt;
	 // set sender&lt;br /&gt;
	eventObj.target = this;&lt;br /&gt;
	// send event&lt;br /&gt;
	this.dispatchEvent ( eventObj );&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;and call it by saying:&lt;br /&gt;
newEvent ( 'someEvent', { prop1:true, prop2:false } );&lt;/p&gt;
&lt;p&gt;Having a myEventfunction ( eventObj:Object ) { } is kinda cool because you never have to worry about the order of your variables in the function, its just ALWAYS going to send an eventObject as a single pram - so give it a point for consistency and predictability.&lt;/p&gt;
&lt;p&gt;By using AsBroadcaster you are getting all events, and those events have to be named the same as you subscribed to. You can choose to not receive events by not making a function of the same name or just unsubscribing to all events. &lt;/p&gt;
&lt;p&gt;I would say the pros include, low overhead in the prams passed. It's probably faster because you spend less time packaging up an object before you send the event, and there is consistency between the event name being broadcast and the method name you use to capture that event.&lt;/p&gt;
&lt;p&gt;The drawback is that you receive all events, you don't know which object sent the event because it doesn't include a reference to itself. That may be ok when you are subscribing to a Mouse or Stage, since there is only one.&lt;/p&gt;

Using the Proxy technique with Event Dispatcher you can easily to the following.
obj1.addEventListener ( 'onPress', mx.utils.Delegate.create ( this, obj1_onPress );
obj2.addEventListener ( 'onPress', obj2_onPress );

See http://www.justgooddesign.com/blog/jgdelegate.htm for more information on delegates.

&lt;p&gt;I guess when it comes down to it, if you have a class witch TONS of events and TONS of subscribers and you only care about a couple of those events per subscriber, or you want to really section out who you subscribed to and tailor the individual method, the use EventDispatcher.&lt;/p&gt;
&lt;p&gt;if you don't need to tailor the event method and it's not that big of a deal to receive all events, all of the time, then use AsBroadcaster.&lt;/p&gt;
&lt;p&gt;Well, that's just my opinion.
&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I tend to use EventDispatcher all the time because of it&#8217;s ability to subscribe/unsubscribe to single events and the way you can proxy those events with a Delegate.</p>
<p>// typical<br />
obj.addEventListener ( &#8217;someEvent&#8217;, this );</p>
<p>// scoped and proxied event<br />
obj.addEventListener ( &#8217;someEvent&#8217;, mx.utils.Delegate.create ( this, myEventfunction );</p>
<p>The advantage of the later is that you can choose the scope and an alternately named function. The overhead occurs when it passes an object with all the information, not limited to the target and type sent by obj, but any property you want to add. </p>
<p>I use this method in my UIEventMovieClip class:<br />
private function newEvent ( type, eventObj:Object ):Void<br />
{<br />
	// check for optional passed prams<br />
	var eventObj = ( eventObj != undefined ) ? eventObj : new Object ();<br />
	// set event type<br />
	eventObj.type = type;<br />
	 // set sender<br />
	eventObj.target = this;<br />
	// send event<br />
	this.dispatchEvent ( eventObj );<br />
}</p>
<p>and call it by saying:<br />
newEvent ( &#8217;someEvent&#8217;, { prop1:true, prop2:false } );</p>
<p>Having a myEventfunction ( eventObj:Object ) { } is kinda cool because you never have to worry about the order of your variables in the function, its just ALWAYS going to send an eventObject as a single pram - so give it a point for consistency and predictability.</p>
<p>By using AsBroadcaster you are getting all events, and those events have to be named the same as you subscribed to. You can choose to not receive events by not making a function of the same name or just unsubscribing to all events. </p>
<p>I would say the pros include, low overhead in the prams passed. It&#8217;s probably faster because you spend less time packaging up an object before you send the event, and there is consistency between the event name being broadcast and the method name you use to capture that event.</p>
<p>The drawback is that you receive all events, you don&#8217;t know which object sent the event because it doesn&#8217;t include a reference to itself. That may be ok when you are subscribing to a Mouse or Stage, since there is only one.</p>
<p>Using the Proxy technique with Event Dispatcher you can easily to the following.<br />
obj1.addEventListener ( &#8216;onPress&#8217;, mx.utils.Delegate.create ( this, obj1_onPress );<br />
obj2.addEventListener ( &#8216;onPress&#8217;, obj2_onPress );</p>
<p>See <a href="http://www.justgooddesign.com/blog/jgdelegate.htm" rel="nofollow">http://www.justgooddesign.com/blog/jgdelegate.htm</a> for more information on delegates.</p>
<p>I guess when it comes down to it, if you have a class witch TONS of events and TONS of subscribers and you only care about a couple of those events per subscriber, or you want to really section out who you subscribed to and tailor the individual method, the use EventDispatcher.</p>
<p>if you don&#8217;t need to tailor the event method and it&#8217;s not that big of a deal to receive all events, all of the time, then use AsBroadcaster.</p>
<p>Well, that&#8217;s just my opinion.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Ed</title>
		<link>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-1292</link>
		<pubDate>Fri, 30 Mar 2007 08:20:29 +0000</pubDate>
		<guid>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-1292</guid>
					<description>I was just wondering about the difference between AsBroadcaster and EventDispatcher myself. I started writing a class and used AsBroadcaster, then just by chance I see this thing called EventDispatcher and I just ground to a halt trying to figure which to use.

For the life of me I can't seem to figure out which one is better to use. The only advantage I can see that EventDispatcher has is the ability to subscribe to specific events, which doesn't seem so hot to me since you could pretty much do the same for AsBroadcaster (i.e. just make callback functions for the eventNames that are of interest for the receiving object).

I'll reread this in the morning and it might become clearer to me, lol. Great site by the way, keep it up!</description>
		<content:encoded><![CDATA[<p>I was just wondering about the difference between AsBroadcaster and EventDispatcher myself. I started writing a class and used AsBroadcaster, then just by chance I see this thing called EventDispatcher and I just ground to a halt trying to figure which to use.</p>
<p>For the life of me I can&#8217;t seem to figure out which one is better to use. The only advantage I can see that EventDispatcher has is the ability to subscribe to specific events, which doesn&#8217;t seem so hot to me since you could pretty much do the same for AsBroadcaster (i.e. just make callback functions for the eventNames that are of interest for the receiving object).</p>
<p>I&#8217;ll reread this in the morning and it might become clearer to me, lol. Great site by the way, keep it up!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: jgraup</title>
		<link>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-496</link>
		<pubDate>Fri, 23 Feb 2007 04:33:47 +0000</pubDate>
		<guid>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-496</guid>
					<description>http://www.helpqlodhelp.com/scripts/com.qlod.ExtendedBroadcaster.as

Extend the built-in broadcaster to allow for 
manipulating the list of listeners during 
the broadcast.
	
Additionally make the broadcaster a real 
class to enable using it like a normal class. 

@author  Ralf Bokelberg
@credits Shinya Tomikawa, Peter Hall, Andre Michelle, Holger Kohnen
	
@lastChange 2003/06/05
	
@history
2003/06/05 published</description>
		<content:encoded><![CDATA[<p><a href="http://www.helpqlodhelp.com/scripts/com.qlod.ExtendedBroadcaster.as" rel="nofollow">http://www.helpqlodhelp.com/scripts/com.qlod.ExtendedBroadcaster.as</a></p>
<p>Extend the built-in broadcaster to allow for<br />
manipulating the list of listeners during<br />
the broadcast.</p>
<p>Additionally make the broadcaster a real<br />
class to enable using it like a normal class. </p>
<p>@author  Ralf Bokelberg<br />
@credits Shinya Tomikawa, Peter Hall, Andre Michelle, Holger Kohnen</p>
<p>@lastChange 2003/06/05</p>
<p>@history<br />
2003/06/05 published
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: jgraup</title>
		<link>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-41</link>
		<pubDate>Thu, 07 Dec 2006 03:03:34 +0000</pubDate>
		<guid>http://www.justgooddesign.com/blog/asbroadcaster-vs-broadcastermx-vs-eventdispatcher.htm#comment-41</guid>
					<description>Check back:
http://www.gskinner.com/blog/archives/000027.html - gDispatcher
http://www.gskinner.com/blog/archives/2003/09/gdispatcher_bug.html
http://www.shocktime.com/eventdispatcher/ - FStEventDispatcherClass
http://stimpson.flashvacuum.net/mt/archives/2005/03/eventcatcher.html - Eventcatcher
http://stimpson.flashvacuum.net/mt/archives/2005/03/eventcatcher_up.html</description>
		<content:encoded><![CDATA[<p>Check back:<br />
<a href="http://www.gskinner.com/blog/archives/000027.html" rel="nofollow">http://www.gskinner.com/blog/archives/000027.html</a> - gDispatcher<br />
<a href="http://www.gskinner.com/blog/archives/2003/09/gdispatcher_bug.html" rel="nofollow">http://www.gskinner.com/blog/archives/2003/09/gdispatcher_bug.html</a><br />
<a href="http://www.shocktime.com/eventdispatcher/" rel="nofollow">http://www.shocktime.com/eventdispatcher/</a> - FStEventDispatcherClass<br />
<a href="http://stimpson.flashvacuum.net/mt/archives/2005/03/eventcatcher.html" rel="nofollow">http://stimpson.flashvacuum.net/mt/archives/2005/03/eventcatcher.html</a> - Eventcatcher<br />
<a href="http://stimpson.flashvacuum.net/mt/archives/2005/03/eventcatcher_up.html" rel="nofollow">http://stimpson.flashvacuum.net/mt/archives/2005/03/eventcatcher_up.html</a>
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
