<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: EventDispatcher Usage Revisited	</title>
	<atom:link href="https://jessewarden.com/2004/03/eventdispatcher-usage-revisited.html/feed" rel="self" type="application/rss+xml" />
	<link>https://jessewarden.com/2004/03/eventdispatcher-usage-revisited.html</link>
	<description>Software &#124; Fitness &#124; Gaming</description>
	<lastBuildDate>Fri, 26 Mar 2004 05:25:38 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>
		By: erikbianchi		</title>
		<link>https://jessewarden.com/2004/03/eventdispatcher-usage-revisited.html/comment-page-1#comment-1503</link>

		<dc:creator><![CDATA[erikbianchi]]></dc:creator>
		<pubDate>Fri, 26 Mar 2004 05:25:38 +0000</pubDate>
		<guid isPermaLink="false">http://jessewarden.com/?p=476#comment-1503</guid>

					<description><![CDATA[oh I see the problem. In the EventDispatcher if what you are adding is a method (function) it applys the function to the queueObj. However, I beleive that applything the method to the queueObj was an oversight. By changeing the apply in the dispatchQueue method from this: 

o.apply(queueObj, [eventObj]);

to this:

o.apply(eventObj.target, [eventObj]);

Allows the event dispatcher to use the proper scope if one is provided. If not the scope remains unchanged from the current functionality.

I&#039;ve come to this conclusion for a couple reasons:

1) everything *seems* to work as intened and scope is being applied correctly. 

2) The following code from the dispatchEvent method seemed odd because it was not being used anywhere else in the class and it logically looked like it would solve any scope issues.

if (eventObj.target == undefined)
eventObj.target = this;

At anyrate here is a working example using my edited EventDispatcher method (free typed in here might be some typos):


// SUBJECT
class Subject
{
	
	// Interface for EventDispatcher
	// didnt want to type a interface, lazy
	public var dispatchEvent:Function;
	public var addEventListener:Function;
	
	// Instance name used to identify scope
	private var name:String = &quot;Subject&quot;;
	
	// Constructor inits Dispatcher
	public function Subject()
	{
		EventDispatcher.initialize(this);
	}
	
	// broadcast the event uses target to pass in scope
	public function triggerUpdate(scope){
		dispatchEvent({type:&quot;update&quot;,target:scope});
	}
	
}



// Observer: Class that Watches Subject
class Observer
{
		
	private var m_Subject:Subject;
	private var name:String = &quot;Observer&quot;;
	
	public function Observer()
	{
		m_Subject = new Subject();
		m_Subject.addEventListener(&quot;update&quot;,onUpdate)
	}
	
	public function onUpdate()
	{
		trace(&quot;Updated: &quot;+name);
	}
	
	// trigger event and passes scope
	public function triggerUpdate()
	{
		m_Subject.triggerUpdate(this);
	}
	
}


// root timeline
var name = &quot;root&quot;;
function update(){
	trace(name);
}

// uses the timeline as the listener
var TestSubject = new Subject();
TestSubject.addEventListener(&quot;update&quot;,update);
TestSubject.update();

// uses a class as the listener
var TestObserver = new Observer();
TestObserver.triggerUpdate();
]]></description>
			<content:encoded><![CDATA[<p>oh I see the problem. In the EventDispatcher if what you are adding is a method (function) it applys the function to the queueObj. However, I beleive that applything the method to the queueObj was an oversight. By changeing the apply in the dispatchQueue method from this: </p>
<p>o.apply(queueObj, [eventObj]);</p>
<p>to this:</p>
<p>o.apply(eventObj.target, [eventObj]);</p>
<p>Allows the event dispatcher to use the proper scope if one is provided. If not the scope remains unchanged from the current functionality.</p>
<p>I&#8217;ve come to this conclusion for a couple reasons:</p>
<p>1) everything *seems* to work as intened and scope is being applied correctly. </p>
<p>2) The following code from the dispatchEvent method seemed odd because it was not being used anywhere else in the class and it logically looked like it would solve any scope issues.</p>
<p>if (eventObj.target == undefined)<br />
eventObj.target = this;</p>
<p>At anyrate here is a working example using my edited EventDispatcher method (free typed in here might be some typos):</p>
<p>// SUBJECT<br />
class Subject<br />
{</p>
<p>	// Interface for EventDispatcher<br />
	// didnt want to type a interface, lazy<br />
	public var dispatchEvent:Function;<br />
	public var addEventListener:Function;</p>
<p>	// Instance name used to identify scope<br />
	private var name:String = &#8220;Subject&#8221;;</p>
<p>	// Constructor inits Dispatcher<br />
	public function Subject()<br />
	{<br />
		EventDispatcher.initialize(this);<br />
	}</p>
<p>	// broadcast the event uses target to pass in scope<br />
	public function triggerUpdate(scope){<br />
		dispatchEvent({type:&#8221;update&#8221;,target:scope});<br />
	}</p>
<p>}</p>
<p>// Observer: Class that Watches Subject<br />
class Observer<br />
{</p>
<p>	private var m_Subject:Subject;<br />
	private var name:String = &#8220;Observer&#8221;;</p>
<p>	public function Observer()<br />
	{<br />
		m_Subject = new Subject();<br />
		m_Subject.addEventListener(&#8220;update&#8221;,onUpdate)<br />
	}</p>
<p>	public function onUpdate()<br />
	{<br />
		trace(&#8220;Updated: &#8220;+name);<br />
	}</p>
<p>	// trigger event and passes scope<br />
	public function triggerUpdate()<br />
	{<br />
		m_Subject.triggerUpdate(this);<br />
	}</p>
<p>}</p>
<p>// root timeline<br />
var name = &#8220;root&#8221;;<br />
function update(){<br />
	trace(name);<br />
}</p>
<p>// uses the timeline as the listener<br />
var TestSubject = new Subject();<br />
TestSubject.addEventListener(&#8220;update&#8221;,update);<br />
TestSubject.update();</p>
<p>// uses a class as the listener<br />
var TestObserver = new Observer();<br />
TestObserver.triggerUpdate();</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: JesterXL		</title>
		<link>https://jessewarden.com/2004/03/eventdispatcher-usage-revisited.html/comment-page-1#comment-1502</link>

		<dc:creator><![CDATA[JesterXL]]></dc:creator>
		<pubDate>Fri, 26 Mar 2004 00:58:32 +0000</pubDate>
		<guid isPermaLink="false">http://jessewarden.com/?p=476#comment-1502</guid>

					<description><![CDATA[It&#039;s all good; I re-read his post based on your suggestion in case I missed something; and indeed I did.  His class is actually a Responder like object that forwards the event.  However, with the amount of event&#039;s I&#039;m registering, I&#039;ve kept to my base class using EventDispatcher, and therefore have little overhead.

...or maybe I&#039;ve switched my event engine too much in my Flash career and am just too tired today to switch again.  Maybe tomorrow.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s all good; I re-read his post based on your suggestion in case I missed something; and indeed I did.  His class is actually a Responder like object that forwards the event.  However, with the amount of event&#8217;s I&#8217;m registering, I&#8217;ve kept to my base class using EventDispatcher, and therefore have little overhead.</p>
<p>&#8230;or maybe I&#8217;ve switched my event engine too much in my Flash career and am just too tired today to switch again.  Maybe tomorrow.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: darron		</title>
		<link>https://jessewarden.com/2004/03/eventdispatcher-usage-revisited.html/comment-page-1#comment-1501</link>

		<dc:creator><![CDATA[darron]]></dc:creator>
		<pubDate>Fri, 26 Mar 2004 00:56:19 +0000</pubDate>
		<guid isPermaLink="false">http://jessewarden.com/?p=476#comment-1501</guid>

					<description><![CDATA[Note to self.  Read your entire post before posting a comment.  ;-)]]></description>
			<content:encoded><![CDATA[<p>Note to self.  Read your entire post before posting a comment.  ;-)</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: darron		</title>
		<link>https://jessewarden.com/2004/03/eventdispatcher-usage-revisited.html/comment-page-1#comment-1500</link>

		<dc:creator><![CDATA[darron]]></dc:creator>
		<pubDate>Fri, 26 Mar 2004 00:52:54 +0000</pubDate>
		<guid isPermaLink="false">http://jessewarden.com/?p=476#comment-1500</guid>

					<description><![CDATA[Use Mike Chamber&#039;s EventProxy: http://www.markme.com/mesh/archives/004286.cfm

usage:
my_btn.addEventListener(&quot;click&quot;, new EventProxy(this, &quot;onButtonClick&quot;));]]></description>
			<content:encoded><![CDATA[<p>Use Mike Chamber&#8217;s EventProxy: <a href="http://www.markme.com/mesh/archives/004286.cfm" rel="nofollow ugc">http://www.markme.com/mesh/archives/004286.cfm</a></p>
<p>usage:<br />
my_btn.addEventListener(&#8220;click&#8221;, new EventProxy(this, &#8220;onButtonClick&#8221;));</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: JesterXL		</title>
		<link>https://jessewarden.com/2004/03/eventdispatcher-usage-revisited.html/comment-page-1#comment-1499</link>

		<dc:creator><![CDATA[JesterXL]]></dc:creator>
		<pubDate>Fri, 26 Mar 2004 00:29:46 +0000</pubDate>
		<guid isPermaLink="false">http://jessewarden.com/?p=476#comment-1499</guid>

					<description><![CDATA[Central is 6.0.65.0, so I don&#039;t really have a choice...]]></description>
			<content:encoded><![CDATA[<p>Central is 6.0.65.0, so I don&#8217;t really have a choice&#8230;</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
