<?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 (AsBroadcaster)</title>
	<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster</link>
	<description>Luck is the residue of good design.</description>
	<pubDate>Wed, 19 Nov 2008 03:59:14 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>

	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-96031</link>
		<pubDate>Thu, 01 Nov 2007 20:06:16 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-96031</guid>
					<description>Dameon,

You might be interested in the &lt;code&gt;OnEnterFrameBeacon&lt;/code&gt; class, then.  Check it out on Darron Schall's &quot;&lt;a href=&quot;http://www.darronschall.com/weblog/archives/000082.cfm&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;A hidden gem... or two&lt;/a&gt;&quot; blog entry.  Pretty neat stuff!</description>
		<content:encoded><![CDATA[<p>Dameon,</p>
<p>You might be interested in the <code>OnEnterFrameBeacon</code> class, then.  Check it out on Darron Schall&#8217;s &#8220;<a href="http://www.darronschall.com/weblog/archives/000082.cfm" target="_blank" rel="nofollow">A hidden gem&#8230; or two</a>&#8221; blog entry.  Pretty neat stuff!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Dameon</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-96014</link>
		<pubDate>Thu, 01 Nov 2007 18:52:06 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-96014</guid>
					<description>Yeah I was wondering the same thing as Andy. My problem is more around the ._alpha property. I'm one of those Flashies who HATES websites that dont use perfect animation. So of course I have OnEnterFrame loops being turned on and off all over the place. I was thinking there may be a way to clean up my code and use events and listeners instead of creating frame loops with conditional statements in them.

However this article gave me some good new ideas not related to that issue.</description>
		<content:encoded><![CDATA[<p>Yeah I was wondering the same thing as Andy. My problem is more around the ._alpha property. I&#8217;m one of those Flashies who HATES websites that dont use perfect animation. So of course I have OnEnterFrame loops being turned on and off all over the place. I was thinking there may be a way to clean up my code and use events and listeners instead of creating frame loops with conditional statements in them.</p>
<p>However this article gave me some good new ideas not related to that issue.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Random &#187; Blog Archive &#187; Creating Custom Events in Flash</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-83404</link>
		<pubDate>Thu, 20 Sep 2007 19:17:56 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-83404</guid>
					<description>[...] I read about it here and here. [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] I read about it here and here. [&#8230;]
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-61075</link>
		<pubDate>Tue, 03 Jul 2007 13:36:41 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-61075</guid>
					<description>Andy,

Thanks.  :)  I hear what you're saying.  The closest you're going to get &amp;#8212; and unfortunately, it won't work in this case &amp;#8212; is the &lt;code&gt;Object.watch()&lt;/code&gt; method.  That &quot;keeps an eye on&quot; object properties and lets you know when they've changed, but it doesn't work for the properties like &lt;code&gt;_y&lt;/code&gt;, and the documentation goes into a brief bit of detail about that.

With regard to &lt;code&gt;ASBroadcaster&lt;/code&gt; and &lt;code&gt;EventDispatcher&lt;/code&gt;, you can indeed listen for events on an as-they-occur basis, it's just that from a programming perspective, part of that scenario involves actually dispatching the event, and only your programming will know when/how to do that.  In some circumstances, &lt;code&gt;Object.watch()&lt;/code&gt; would allow you to dispatch the event; in others, it may take a loop; in yet others, user input, and so forth.</description>
		<content:encoded><![CDATA[<p>Andy,</p>
<p>Thanks.  <img src='http://www.quip.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   I hear what you&#8217;re saying.  The closest you&#8217;re going to get &mdash; and unfortunately, it won&#8217;t work in this case &mdash; is the <code>Object.watch()</code> method.  That &#8220;keeps an eye on&#8221; object properties and lets you know when they&#8217;ve changed, but it doesn&#8217;t work for the properties like <code>_y</code>, and the documentation goes into a brief bit of detail about that.</p>
<p>With regard to <code>ASBroadcaster</code> and <code>EventDispatcher</code>, you can indeed listen for events on an as-they-occur basis, it&#8217;s just that from a programming perspective, part of that scenario involves actually dispatching the event, and only your programming will know when/how to do that.  In some circumstances, <code>Object.watch()</code> would allow you to dispatch the event; in others, it may take a loop; in yet others, user input, and so forth.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Andy</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-60162</link>
		<pubDate>Fri, 29 Jun 2007 20:46:19 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-60162</guid>
					<description>Hi David,

Thanks again for your response.
I thought your article was well written. It got me thinking and this isn't the first time I've tried to get software to do something that it maybe can't do.
I've always used frameloops. But they aren't very elegant for checking on multiple conditions. I have used setInterval but I find that they can also be a dangerous situation when using multiple intervals.

Why I feel I don't understand the broadcaster/listener concept is that I'm expecting to be able to write a custom event such as (mc1._y == 150) and have ASBroadcaster take the place of the frameloop.

In my understanding, if I add a custom event to ASBroadcaster, I would like to see ASBroadcaster watch for my custom event whenever it occurs. (Just as it will sit and wait for a mouse click). When it does occur, it would broadcast that it has occurred to any registered listeners (mc2) to run a function a single time.

I'm not certain this can be done but I appreciate your thoughts on this.
It's a long weekend here in Canada so I won't have to worry for a few days about making pixels fly.

Thanks again,</description>
		<content:encoded><![CDATA[<p>Hi David,</p>
<p>Thanks again for your response.<br />
I thought your article was well written. It got me thinking and this isn&#8217;t the first time I&#8217;ve tried to get software to do something that it maybe can&#8217;t do.<br />
I&#8217;ve always used frameloops. But they aren&#8217;t very elegant for checking on multiple conditions. I have used setInterval but I find that they can also be a dangerous situation when using multiple intervals.</p>
<p>Why I feel I don&#8217;t understand the broadcaster/listener concept is that I&#8217;m expecting to be able to write a custom event such as (mc1._y == 150) and have ASBroadcaster take the place of the frameloop.</p>
<p>In my understanding, if I add a custom event to ASBroadcaster, I would like to see ASBroadcaster watch for my custom event whenever it occurs. (Just as it will sit and wait for a mouse click). When it does occur, it would broadcast that it has occurred to any registered listeners (mc2) to run a function a single time.</p>
<p>I&#8217;m not certain this can be done but I appreciate your thoughts on this.<br />
It&#8217;s a long weekend here in Canada so I won&#8217;t have to worry for a few days about making pixels fly.</p>
<p>Thanks again,
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-60094</link>
		<pubDate>Fri, 29 Jun 2007 13:28:40 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-60094</guid>
					<description>Andy,

If you have a sense of confusion in this particular context, the likeliest bet is that I failed to write the above blog entry as clearly as I could or should have.  I &lt;em&gt;think&lt;/em&gt; you're asking me, &quot;I'd prefer not to have so many loops.  Loops, in this case, are based on the &lt;code&gt;onEnterFrame&lt;/code&gt; event, and I don't want to use &lt;em&gt;that&lt;/em&gt; event &amp;#8212; I'd like to dispatch an event of my own.&quot;  Conceptually, that makes sense to me.

You certainly &lt;em&gt;can&lt;/em&gt; generate a completely custom event, and you can generate it whenever you like.  You're saying the event should be dispatched every time a certain movie clip's &lt;code&gt;_y&lt;/code&gt; property hits a certain value.  Practically speaking, the only way your code will know when this value has been attained is to check that &lt;code&gt;_y&lt;/code&gt; property repeatedly.  If you're animating that clip programmatically, then you presumably already have a looping mechanism in place.  By using that mechanism to dispatch your event, you can avoid having a &lt;em&gt;second&lt;/em&gt; loop that checks the &lt;code&gt;_y&lt;/code&gt; position for you.

If you're not using ActionScript to animate that clip, then you may be able to dispatch your event from whatever keyframe represents the &lt;code&gt;_y&lt;/code&gt; position you're after.

But the problem here may simply be the examples I alluded to in the blog entry itself.  See &quot;&lt;a href=&quot;http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part2&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Loading and Tracking Multiple Files at the Same Time (Part 2)&lt;/a&gt;&quot; for an example that may make more sense.  :)</description>
		<content:encoded><![CDATA[<p>Andy,</p>
<p>If you have a sense of confusion in this particular context, the likeliest bet is that I failed to write the above blog entry as clearly as I could or should have.  I <em>think</em> you&#8217;re asking me, &#8220;I&#8217;d prefer not to have so many loops.  Loops, in this case, are based on the <code>onEnterFrame</code> event, and I don&#8217;t want to use <em>that</em> event &mdash; I&#8217;d like to dispatch an event of my own.&#8221;  Conceptually, that makes sense to me.</p>
<p>You certainly <em>can</em> generate a completely custom event, and you can generate it whenever you like.  You&#8217;re saying the event should be dispatched every time a certain movie clip&#8217;s <code>_y</code> property hits a certain value.  Practically speaking, the only way your code will know when this value has been attained is to check that <code>_y</code> property repeatedly.  If you&#8217;re animating that clip programmatically, then you presumably already have a looping mechanism in place.  By using that mechanism to dispatch your event, you can avoid having a <em>second</em> loop that checks the <code>_y</code> position for you.</p>
<p>If you&#8217;re not using ActionScript to animate that clip, then you may be able to dispatch your event from whatever keyframe represents the <code>_y</code> position you&#8217;re after.</p>
<p>But the problem here may simply be the examples I alluded to in the blog entry itself.  See &#8220;<a href="http://www.quip.net/blog/2007/flash/actionscript-20/tracking-multiple-files-part2" target="_blank" rel="nofollow">Loading and Tracking Multiple Files at the Same Time (Part 2)</a>&#8221; for an example that may make more sense.  <img src='http://www.quip.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Andy</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-60085</link>
		<pubDate>Fri, 29 Jun 2007 12:50:46 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-60085</guid>
					<description>Hi David,

Perhaps I'm not understanding the broadcast-listener model correctly.
I thought that I might be able to get ASBroadcaster to check for _y and through writing a custom event (ie: _y == 150) broadcast the magic moment so that another MC I want to register as a listener will then start a function.

With the frameloop, I have to place a switch statement within it to check for a variable I toggle so that the frameloop doesn't continuely call the function I want to run only once. This doesn't strike me as very elegant but it works.
This particular situation is fine as it only involves two MCs but I think this method wouldn't work very well if I had multiple MCs with conditions to check as was the case with your game example.

I thought if I could use ASBroadcaster or DispatchEvent to check for a recurring specific condition and broadcast accordingly that it could eliminate the need for frameloops entirely.

Thanks again for your responses,</description>
		<content:encoded><![CDATA[<p>Hi David,</p>
<p>Perhaps I&#8217;m not understanding the broadcast-listener model correctly.<br />
I thought that I might be able to get ASBroadcaster to check for _y and through writing a custom event (ie: _y == 150) broadcast the magic moment so that another MC I want to register as a listener will then start a function.</p>
<p>With the frameloop, I have to place a switch statement within it to check for a variable I toggle so that the frameloop doesn&#8217;t continuely call the function I want to run only once. This doesn&#8217;t strike me as very elegant but it works.<br />
This particular situation is fine as it only involves two MCs but I think this method wouldn&#8217;t work very well if I had multiple MCs with conditions to check as was the case with your game example.</p>
<p>I thought if I could use ASBroadcaster or DispatchEvent to check for a recurring specific condition and broadcast accordingly that it could eliminate the need for frameloops entirely.</p>
<p>Thanks again for your responses,
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-59941</link>
		<pubDate>Thu, 28 Jun 2007 16:12:50 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-59941</guid>
					<description>Andy,

If you don't want to use &lt;code&gt;onEnterFrame&lt;/code&gt; to check, you could certainly use &lt;code&gt;setInterval()&lt;/code&gt; &amp;#8212; but heck, if you're &lt;em&gt;already&lt;/em&gt; employing a loop, put it to work for you!  ;)

I don't mean to suggest that loops are essentially bad things &amp;#8212; I hope the article doesn't push that point too strongly &amp;#8212; but in this case, if the &lt;code&gt;_y&lt;/code&gt; position isn't dependent on user interaction, you've got to check for it somehow, and presumably repeatedly.

Custom events can be broadcast whenever you please; that's the benefit they bring to the table.  In the article above, the dispatch occurs based on an &lt;code&gt;onRelease&lt;/code&gt; event, which happens to be user-dependent.  But the choice is yours.  You're already checking the &lt;code&gt;_y&lt;/code&gt; position, apparently on a recurring basis (frame loop), so as you do so, dispatch an event when &lt;code&gt;_y&lt;/code&gt; hits the magic spot.</description>
		<content:encoded><![CDATA[<p>Andy,</p>
<p>If you don&#8217;t want to use <code>onEnterFrame</code> to check, you could certainly use <code>setInterval()</code> &mdash; but heck, if you&#8217;re <em>already</em> employing a loop, put it to work for you!  <img src='http://www.quip.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I don&#8217;t mean to suggest that loops are essentially bad things &mdash; I hope the article doesn&#8217;t push that point too strongly &mdash; but in this case, if the <code>_y</code> position isn&#8217;t dependent on user interaction, you&#8217;ve got to check for it somehow, and presumably repeatedly.</p>
<p>Custom events can be broadcast whenever you please; that&#8217;s the benefit they bring to the table.  In the article above, the dispatch occurs based on an <code>onRelease</code> event, which happens to be user-dependent.  But the choice is yours.  You&#8217;re already checking the <code>_y</code> position, apparently on a recurring basis (frame loop), so as you do so, dispatch an event when <code>_y</code> hits the magic spot.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Andy</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-59940</link>
		<pubDate>Thu, 28 Jun 2007 16:05:06 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-59940</guid>
					<description>Hi David,

Thank you for the reply. As in your article, I'm trying to avoid using any sort of frame loop. I am currently using an onEnterFrame loop to check the _y of the MC.

Is there a way to code a custom condition to broadcast a custom event without any sort of user input?

Thanks again,</description>
		<content:encoded><![CDATA[<p>Hi David,</p>
<p>Thank you for the reply. As in your article, I&#8217;m trying to avoid using any sort of frame loop. I am currently using an onEnterFrame loop to check the _y of the MC.</p>
<p>Is there a way to code a custom condition to broadcast a custom event without any sort of user input?</p>
<p>Thanks again,
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-59839</link>
		<pubDate>Thu, 28 Jun 2007 03:30:39 +0000</pubDate>
		<guid>http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster#comment-59839</guid>
					<description>Andy,

You've got two choices, here.  You can either broadcast the event any old time, and let the receiving object determine whether or not it cares (use &lt;code&gt;if&lt;/code&gt; in the listener) &amp;#8212; or you can broadcast the event only when a particular condition is met, which is what you're leaning toward, it sounds like.

In the article itself, I programmed the event to be dispatched in response to an &lt;code&gt;onRelease&lt;/code&gt; event, and then dependent on an &lt;code&gt;if&lt;/code&gt; statement.  In your case, you might use an &lt;code&gt;onEnterFrame&lt;/code&gt; event (or maybe &lt;code&gt;setInterval()&lt;/code&gt;) to repeatedly check the &lt;code&gt;_y&lt;/code&gt; position of your movie clip.  Inside that loop, use an &lt;code&gt;if&lt;/code&gt; statement of your own to evaluate the value of &lt;code&gt;_y&lt;/code&gt;.</description>
		<content:encoded><![CDATA[<p>Andy,</p>
<p>You&#8217;ve got two choices, here.  You can either broadcast the event any old time, and let the receiving object determine whether or not it cares (use <code>if</code> in the listener) &mdash; or you can broadcast the event only when a particular condition is met, which is what you&#8217;re leaning toward, it sounds like.</p>
<p>In the article itself, I programmed the event to be dispatched in response to an <code>onRelease</code> event, and then dependent on an <code>if</code> statement.  In your case, you might use an <code>onEnterFrame</code> event (or maybe <code>setInterval()</code>) to repeatedly check the <code>_y</code> position of your movie clip.  Inside that loop, use an <code>if</code> statement of your own to evaluate the value of <code>_y</code>.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
