<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: How to Raise Custom Events (EventDispatcher)</title>
	<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher</link>
	<description>Luck is the residue of good design.</description>
	<pubDate>Mon, 08 Sep 2008 01:06:38 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>

	<item>
		<title>by: Michael de Nigris</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-26105</link>
		<pubDate>Wed, 21 Mar 2007 13:06:04 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-26105</guid>
					<description>Thanks David.  Makes perfect sense, and your suggestion worked perfectly.  By the way, I am using the data parameter, however, I had removed it during debugging attempts to simplify the problem.

xsMCE.onData = Delegate.create(this, function(sData:String) {
    var eventObject:Object = target:this, type:&quot;onDataReceived&quot;, stream:sData};
    this.dispatchEvent(eventObject);
});

Thanks for the insight.</description>
		<content:encoded><![CDATA[<p>Thanks David.  Makes perfect sense, and your suggestion worked perfectly.  By the way, I am using the data parameter, however, I had removed it during debugging attempts to simplify the problem.</p>
<p>xsMCE.onData = Delegate.create(this, function(sData:String) {<br />
    var eventObject:Object = target:this, type:&#8221;onDataReceived&#8221;, stream:sData};<br />
    this.dispatchEvent(eventObject);<br />
});</p>
<p>Thanks for the insight.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-25960</link>
		<pubDate>Wed, 21 Mar 2007 05:02:03 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-25960</guid>
					<description>Michael,

What you're seeing is the result of how that function is scoped.  The global &lt;code&gt;this&lt;/code&gt; property is scoped to the &lt;code&gt;MyXMLSocket&lt;/code&gt; object by way of the anonymous function. Its &quot;point of view,&quot; therefore, is the &lt;code&gt;MyXMLSocket&lt;/code&gt; object, which almost certainly doesn't feature a &lt;code&gt;dispatchEvent()&lt;/code&gt; method.  Make sense?

In a case like this the &lt;code&gt;Delegate&lt;/code&gt; class is a good idea.  Import &lt;code&gt;import mx.utils.Delegate;&lt;/code&gt; before your class declaration, then replace that function with this ...

&lt;pre&gt;&lt;code&gt;MyXMLSocket.onData = Delegate.create(this, function() {
  var eventObject:Object = {target:this, type:”onDataReceived”};
  dispatchEvent(eventObject);
});&lt;/code&gt;&lt;/pre&gt;

What this does is re-route the scope of your function to the class itself, which &lt;em&gt;does&lt;/em&gt; support a &lt;code&gt;dispatchEvent()&lt;/code&gt; method, assuming you used &lt;code&gt;EventDispatcher.initialize(this);&lt;/code&gt; in the constructor.

Note:  It didn't appear you were using the &lt;code&gt;sData&lt;/code&gt; parameter, so I dropped it.</description>
		<content:encoded><![CDATA[<p>Michael,</p>
<p>What you&#8217;re seeing is the result of how that function is scoped.  The global <code>this</code> property is scoped to the <code>MyXMLSocket</code> object by way of the anonymous function. Its &#8220;point of view,&#8221; therefore, is the <code>MyXMLSocket</code> object, which almost certainly doesn&#8217;t feature a <code>dispatchEvent()</code> method.  Make sense?</p>
<p>In a case like this the <code>Delegate</code> class is a good idea.  Import <code>import mx.utils.Delegate;</code> before your class declaration, then replace that function with this &#8230;</p>
<pre><code>MyXMLSocket.onData = Delegate.create(this, function() {
  var eventObject:Object = {target:this, type:”onDataReceived”};
  dispatchEvent(eventObject);
});</code></pre>
<p>What this does is re-route the scope of your function to the class itself, which <em>does</em> support a <code>dispatchEvent()</code> method, assuming you used <code>EventDispatcher.initialize(this);</code> in the constructor.</p>
<p>Note:  It didn&#8217;t appear you were using the <code>sData</code> parameter, so I dropped it.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Michael de Nigris</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-25937</link>
		<pubDate>Wed, 21 Mar 2007 04:30:18 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-25937</guid>
					<description>David,

Thanks for the informative article.  I've successfuly implemented custom events with a class, but I'm having trouble dispatching an event from within an anonymous function (another event handler) within the class.

For instance, this code does not seem to reach the listeners outside the class.

MyXMLSocket.onData = function(sData:String){
  var eventObject:Object = {target:this, type:&quot;onDataReceived&quot;};
  this.dispatchEvent(eventObject);
}

Any clue what I'm doing wrong?</description>
		<content:encoded><![CDATA[<p>David,</p>
<p>Thanks for the informative article.  I&#8217;ve successfuly implemented custom events with a class, but I&#8217;m having trouble dispatching an event from within an anonymous function (another event handler) within the class.</p>
<p>For instance, this code does not seem to reach the listeners outside the class.</p>
<p>MyXMLSocket.onData = function(sData:String){<br />
  var eventObject:Object = {target:this, type:&#8221;onDataReceived&#8221;};<br />
  this.dispatchEvent(eventObject);<br />
}</p>
<p>Any clue what I&#8217;m doing wrong?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-6984</link>
		<pubDate>Fri, 01 Dec 2006 22:42:40 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-6984</guid>
					<description>Ed,

It sounds like we don't have a whole lot in common, but I'm happy if this blog entry helped you.

I enjoy the occasional venture into other territory, be it C#, Java, Python, PHP ... I have my hunch which of the above you'd consider &quot;real,&quot; but in many ways, it's just a matter of where and how you care to spend your time.

I'm certainly thankful for developers who spend their efforts in lower level languages, because they allow me to do the things that float my boat.  I'd say there's plenty of elbow room for whoever wants to dive in.

Have you checked out Flex and ActionScript 3.0?  I think you'll find there's quite a difference.</description>
		<content:encoded><![CDATA[<p>Ed,</p>
<p>It sounds like we don&#8217;t have a whole lot in common, but I&#8217;m happy if this blog entry helped you.</p>
<p>I enjoy the occasional venture into other territory, be it C#, Java, Python, PHP &#8230; I have my hunch which of the above you&#8217;d consider &#8220;real,&#8221; but in many ways, it&#8217;s just a matter of where and how you care to spend your time.</p>
<p>I&#8217;m certainly thankful for developers who spend their efforts in lower level languages, because they allow me to do the things that float my boat.  I&#8217;d say there&#8217;s plenty of elbow room for whoever wants to dive in.</p>
<p>Have you checked out Flex and ActionScript 3.0?  I think you&#8217;ll find there&#8217;s quite a difference.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Ed Hassinger</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-6977</link>
		<pubDate>Fri, 01 Dec 2006 20:21:11 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-6977</guid>
					<description>Flash sucks.  As such you took a great topic and gave a concise example that someone using a real programming language/IDE could work with it quickly.

Kudos.</description>
		<content:encoded><![CDATA[<p>Flash sucks.  As such you took a great topic and gave a concise example that someone using a real programming language/IDE could work with it quickly.</p>
<p>Kudos.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-2456</link>
		<pubDate>Fri, 08 Sep 2006 16:21:09 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-2456</guid>
					<description>Dom,

Thanks for the kind words!  :)

As far as I know, there is not a way to cancel a web request in AS1/AS2 until it times out on its own (and you're right, there is no &lt;code&gt;timeout&lt;/code&gt; property &amp;#8212; that has always baffled me).  I seem to remember a Flashcoders workaround suggestion ... something along the lines of requesting a new, known-good, very small file to &quot;cancel&quot; the pending request, but I'm afraid the details are hazy in my memory.

I was about to suggest that you use &lt;code&gt;setInterval()&lt;/code&gt; or &lt;code&gt;setTimeout()&lt;/code&gt; [undocumented], when I saw your follow up post.  ;)  To my thinking, you're on the right track.  Good luck with that!</description>
		<content:encoded><![CDATA[<p>Dom,</p>
<p>Thanks for the kind words!  <img src='http://www.quip.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>As far as I know, there is not a way to cancel a web request in AS1/AS2 until it times out on its own (and you&#8217;re right, there is no <code>timeout</code> property &mdash; that has always baffled me).  I seem to remember a Flashcoders workaround suggestion &#8230; something along the lines of requesting a new, known-good, very small file to &#8220;cancel&#8221; the pending request, but I&#8217;m afraid the details are hazy in my memory.</p>
<p>I was about to suggest that you use <code>setInterval()</code> or <code>setTimeout()</code> [undocumented], when I saw your follow up post.  <img src='http://www.quip.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   To my thinking, you&#8217;re on the right track.  Good luck with that!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Dominic Turner</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-2450</link>
		<pubDate>Fri, 08 Sep 2006 15:22:05 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-2450</guid>
					<description>Well - further to my last - there is no timeout property in Flash 8 either (although there is still a timeout faultcode??????) but i have been able to accomplish a cancel by using removeEventListener for the status and result events.</description>
		<content:encoded><![CDATA[<p>Well - further to my last - there is no timeout property in Flash 8 either (although there is still a timeout faultcode??????) but i have been able to accomplish a cancel by using removeEventListener for the status and result events.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Dominic Turner</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-2443</link>
		<pubDate>Fri, 08 Sep 2006 11:38:11 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-2443</guid>
					<description>Hi there David,

I have read your two articles about custom events and they have been really helpful and influenced me greatly in how I go about writing my flash projects. It is a much cleaner way of doing things than my current dodgy sub-movie loops to try and work out whether something has happened.

However I have a problem that I don't know if you can shed some light on. I am using the webserviceconnector class to connect to an asp.net webservice. Sometimes my webservice takes forever or hangs, and I would like to give the user a way of cancelling the webrequest.

There don't seem to be any methods for &quot;abort&quot; so I was thinking would it be possible to raise an event for the connector - i.e. raise an error event, so that I can stop it? If there is any other simpler way that you know of I would love to know - am scratching my head with this one...

Many thanks - great article,

Dom.</description>
		<content:encoded><![CDATA[<p>Hi there David,</p>
<p>I have read your two articles about custom events and they have been really helpful and influenced me greatly in how I go about writing my flash projects. It is a much cleaner way of doing things than my current dodgy sub-movie loops to try and work out whether something has happened.</p>
<p>However I have a problem that I don&#8217;t know if you can shed some light on. I am using the webserviceconnector class to connect to an asp.net webservice. Sometimes my webservice takes forever or hangs, and I would like to give the user a way of cancelling the webrequest.</p>
<p>There don&#8217;t seem to be any methods for &#8220;abort&#8221; so I was thinking would it be possible to raise an event for the connector - i.e. raise an error event, so that I can stop it? If there is any other simpler way that you know of I would love to know - am scratching my head with this one&#8230;</p>
<p>Many thanks - great article,</p>
<p>Dom.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-1326</link>
		<pubDate>Wed, 26 Jul 2006 13:52:00 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-1326</guid>
					<description>eRez,

Really, the choice is yours.  Personally, I prefer &lt;code&gt;EventDispatcher&lt;/code&gt;, but that's only because it sends an event object with optional arguments supplied as object parameters, rather than just as arguments.  But really, that's like saying I prefer coffee ice cream because it tastes like coffee, rather than vanilla.

For what it's worth, the v2 Components that ship with Flash use &lt;code&gt;EventDispatcher&lt;/code&gt; -- but honestly, just use the one that makes more sense to you.</description>
		<content:encoded><![CDATA[<p>eRez,</p>
<p>Really, the choice is yours.  Personally, I prefer <code>EventDispatcher</code>, but that&#8217;s only because it sends an event object with optional arguments supplied as object parameters, rather than just as arguments.  But really, that&#8217;s like saying I prefer coffee ice cream because it tastes like coffee, rather than vanilla.</p>
<p>For what it&#8217;s worth, the v2 Components that ship with Flash use <code>EventDispatcher</code> &#8212; but honestly, just use the one that makes more sense to you.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: eRez</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-1310</link>
		<pubDate>Wed, 26 Jul 2006 07:30:28 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher#comment-1310</guid>
					<description>other than minor syntax differences, in what other way does eventDispatcher differs from the asBroadcaster?
or in other words - when do i use this and when do i use the other?</description>
		<content:encoded><![CDATA[<p>other than minor syntax differences, in what other way does eventDispatcher differs from the asBroadcaster?<br />
or in other words - when do i use this and when do i use the other?
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
