<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Passing Arguments with Events</title>
	<link>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/</link>
	<description>A digital supplement for the O'Reilly book</description>
	<pubDate>Fri, 30 Jul 2010 13:40:19 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Rich</title>
		<link>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-5952</link>
		<dc:creator>Rich</dc:creator>
		<pubDate>Wed, 24 Feb 2010 15:44:53 +0000</pubDate>
		<guid>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-5952</guid>
		<description>@Tino, thanks for posting!</description>
		<content:encoded><![CDATA[<p>@Tino, thanks for posting!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tino</title>
		<link>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-5890</link>
		<dc:creator>Tino</dc:creator>
		<pubDate>Thu, 18 Feb 2010 14:30:24 +0000</pubDate>
		<guid>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-5890</guid>
		<description>Here is an approach I use when I want to pass arguments with events. It's kind of similar to Jonathon's, but I thought it worth posting. I find this useful for testing things and if I am in a rush and various other times!

Example 1.
This is when I want to bind activity to one particular event of one display object:

&lt;pre class="code"&gt;
btn.addEventListener(MouseEvent.CLICK, tempfn)
function tempfn(e:Event):void
{
	trace('btn title')
}
&lt;/pre&gt;

Example 2.

If you want to do this for more than one object..

Use a literal function (I think that's the right term). Any road, in the example below, when the user clicks on 'btn', or 'btn2', the statements within the function literal tempfn - declared as the function for the event - will fire.

&lt;pre class="code"&gt;
btn.addEventListener(MouseEvent.CLICK, function tempfn(e:Event):void{ trace('btn title') } )
btn2.addEventListener(MouseEvent.CLICK, function tempfn(e:Event):void{ trace('btn2 title') } )
&lt;/pre&gt;

So if you replace the body of tempfn with functions to update a text field or load an image and pass params to these functions like the example below...you have a way of getting events to do bespoke things quickly.

&lt;pre class="code"&gt;
btn.addEventListener(MouseEvent.CLICK, function tempfn(e:Event):void{ updateTf('btn title'), loadImage('imageName.jpg') } )
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Here is an approach I use when I want to pass arguments with events. It&#8217;s kind of similar to Jonathon&#8217;s, but I thought it worth posting. I find this useful for testing things and if I am in a rush and various other times!</p>
<p>Example 1.<br />
This is when I want to bind activity to one particular event of one display object:</p>
<pre class="code">
btn.addEventListener(MouseEvent.CLICK, tempfn)
function tempfn(e:Event):void
{
	trace('btn title')
}
</pre>
<p>Example 2.</p>
<p>If you want to do this for more than one object..</p>
<p>Use a literal function (I think that&#8217;s the right term). Any road, in the example below, when the user clicks on &#8216;btn&#8217;, or &#8216;btn2&#8242;, the statements within the function literal tempfn - declared as the function for the event - will fire.</p>
<pre class="code">
btn.addEventListener(MouseEvent.CLICK, function tempfn(e:Event):void{ trace('btn title') } )
btn2.addEventListener(MouseEvent.CLICK, function tempfn(e:Event):void{ trace('btn2 title') } )
</pre>
<p>So if you replace the body of tempfn with functions to update a text field or load an image and pass params to these functions like the example below&#8230;you have a way of getting events to do bespoke things quickly.</p>
<pre class="code">
btn.addEventListener(MouseEvent.CLICK, function tempfn(e:Event):void{ updateTf('btn title'), loadImage('imageName.jpg') } )
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: John laPlante</title>
		<link>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3972</link>
		<dc:creator>John laPlante</dc:creator>
		<pubDate>Tue, 22 Sep 2009 13:14:38 +0000</pubDate>
		<guid>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3972</guid>
		<description>@Rich, thanks for that tip. I spent some time looking at MouseEvent and I see that is the avenue I would need to go down. The crux of my point is that adding a dispatch statement to a callback method requires that work everytime. I was inquiring into solutions that are more general and that a developer could setup once and use over and over. I will look into this some more and maybe post back.</description>
		<content:encoded><![CDATA[<p>@Rich, thanks for that tip. I spent some time looking at MouseEvent and I see that is the avenue I would need to go down. The crux of my point is that adding a dispatch statement to a callback method requires that work everytime. I was inquiring into solutions that are more general and that a developer could setup once and use over and over. I will look into this some more and maybe post back.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Farzan mc</title>
		<link>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3966</link>
		<dc:creator>Farzan mc</dc:creator>
		<pubDate>Tue, 22 Sep 2009 04:22:16 +0000</pubDate>
		<guid>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3966</guid>
		<description>Hello. This was a great article. I was googling for this, i think for months but i couldn't find exactly what i wanted. Passing arquments with custom events is so helpfull and  handy in designing websites.
Thank you.</description>
		<content:encoded><![CDATA[<p>Hello. This was a great article. I was googling for this, i think for months but i couldn&#8217;t find exactly what i wanted. Passing arquments with custom events is so helpfull and  handy in designing websites.<br />
Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rich</title>
		<link>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3952</link>
		<dc:creator>Rich</dc:creator>
		<pubDate>Mon, 21 Sep 2009 12:18:20 +0000</pubDate>
		<guid>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3952</guid>
		<description>@John, can you clarify a bit? You wouldn't extend the button class to accomplish what you're describing. You seem to be describing something like this: First, add an event called EXTENDED_CLICK to the MouseEvent class. Next add a String (or untyped) parameter to that class so you can pass data along with the event. Last, make the new event dispatch via the mouse? Does that sound right?</description>
		<content:encoded><![CDATA[<p>@John, can you clarify a bit? You wouldn&#8217;t extend the button class to accomplish what you&#8217;re describing. You seem to be describing something like this: First, add an event called EXTENDED_CLICK to the MouseEvent class. Next add a String (or untyped) parameter to that class so you can pass data along with the event. Last, make the new event dispatch via the mouse? Does that sound right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John laPlante</title>
		<link>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3835</link>
		<dc:creator>John laPlante</dc:creator>
		<pubDate>Mon, 14 Sep 2009 15:13:53 +0000</pubDate>
		<guid>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3835</guid>
		<description>I found the article valuable for explaining how to dispatch custom events. That certainly seems easier in AS3 than AS2 but in any case very useful. I agree that the example is one that would be hard to justify unless there was some serious scaling issues. For a simple Flash movie, the simpler approaches would be awful appealing. The one thing that I'd like to see is an explanation how to extend the button class so that I could do something like follow:

regBtn.addEventListener(MouseEvent.EXTENDED_CLICK, onReg, "Claire", false, 0, true);

This apppoach might be a lot of work behind the scenes to setup but thereafter, I could use the EXTENDED_CLICK event whenever I have a button.</description>
		<content:encoded><![CDATA[<p>I found the article valuable for explaining how to dispatch custom events. That certainly seems easier in AS3 than AS2 but in any case very useful. I agree that the example is one that would be hard to justify unless there was some serious scaling issues. For a simple Flash movie, the simpler approaches would be awful appealing. The one thing that I&#8217;d like to see is an explanation how to extend the button class so that I could do something like follow:</p>
<p>regBtn.addEventListener(MouseEvent.EXTENDED_CLICK, onReg, &#8220;Claire&#8221;, false, 0, true);</p>
<p>This apppoach might be a lot of work behind the scenes to setup but thereafter, I could use the EXTENDED_CLICK event whenever I have a button.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Passing Arguments with CustomEvents &#124; Andy D</title>
		<link>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3562</link>
		<dc:creator>Passing Arguments with CustomEvents &#124; Andy D</dc:creator>
		<pubDate>Sun, 16 Aug 2009 07:49:53 +0000</pubDate>
		<guid>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3562</guid>
		<description>[...] good examples; 1. http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/ 2. http://evolve.reintroducing.com/2007/10/23/as3/as3-custom-events/    Categories: Uncategorized [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] good examples; 1. <a href="http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/" rel="nofollow">http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/</a> 2. <a href="http://evolve.reintroducing.com/2007/10/23/as3/as3-custom-events/" rel="nofollow">http://evolve.reintroducing.com/2007/10/23/as3/as3-custom-events/</a>    Categories: Uncategorized [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sigmund Øvrum</title>
		<link>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3299</link>
		<dc:creator>Sigmund Øvrum</dc:creator>
		<pubDate>Tue, 07 Jul 2009 11:03:12 +0000</pubDate>
		<guid>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3299</guid>
		<description>Wow - I'm terribly SORRY!!! I just found out what I did wrong. I have to write it like this: myLoader.content.dispatchEvent(new MyCustomEvent( MyCustomEvent.NEW_PAGE, "video"();

I did, and now it works.

Thanks anyway, for reading all this shit.

Yours humbled
Sigmund</description>
		<content:encoded><![CDATA[<p>Wow - I&#8217;m terribly SORRY!!! I just found out what I did wrong. I have to write it like this: myLoader.content.dispatchEvent(new MyCustomEvent( MyCustomEvent.NEW_PAGE, &#8220;video&#8221;();</p>
<p>I did, and now it works.</p>
<p>Thanks anyway, for reading all this shit.</p>
<p>Yours humbled<br />
Sigmund</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sigmund Øvrum</title>
		<link>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3298</link>
		<dc:creator>Sigmund Øvrum</dc:creator>
		<pubDate>Tue, 07 Jul 2009 10:24:42 +0000</pubDate>
		<guid>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3298</guid>
		<description>Hi. Thank you for these turotials, they are very thorough and well laid out. I can't seem to make the Custom Event class to work properly in my testproject though. This is a project where I try to get to grips with deeplinking with SWFAddress. I have tested the relevant issues and SWFAddress seem to be working as intended. 

I have a main.swf which loads a numberOne.swf when I click a button. The numberOne.swf in turn loads a numerOneB.swf when the appropriate button is clicked. When I click a button in numberOneB the SWFAddress value is set to for instance "/NumberOne?page=video". The listener for the SWFAddresssEvent.CHANGE in main.swf trigger a function that checks the value of SWFAddress. If the value is "/NumberOne?page=video" it dispatches an event using my new custom class from main.swf with an argument (a string).

I also have a listener in the constructor in the document class of numberOne.swf which listens for dispatches through my custom event class and then trigger a function.  This function currently just writes to a Textfield in main.swf but it is meant to load the appropriate movieClips or .swf's depending on which argument is passed.

The custom class seem to be set up correctly; I get no errors, and it works as expected if i put the listener and its function inside main.swf. But I get no action when I put the listener inside numberOne.swf. I get the correct SWFAddress-value passed from numberOne.swf to main.swf, but I don't get the argument from the custom event class. 

Can you see any obvious fault in this outline. The whole thing is laid out on http://nrksuper.no/superstore/flashfiles/sigtest/dyplenking/ so you can see that it works (somehow) if you like. The file names are in Norwegian so they don't totally correspond with the names I've used above.

I hope this isn't taking too much of your time

Kind regards
Sigmund Øvrum</description>
		<content:encoded><![CDATA[<p>Hi. Thank you for these turotials, they are very thorough and well laid out. I can&#8217;t seem to make the Custom Event class to work properly in my testproject though. This is a project where I try to get to grips with deeplinking with SWFAddress. I have tested the relevant issues and SWFAddress seem to be working as intended. </p>
<p>I have a main.swf which loads a numberOne.swf when I click a button. The numberOne.swf in turn loads a numerOneB.swf when the appropriate button is clicked. When I click a button in numberOneB the SWFAddress value is set to for instance &#8220;/NumberOne?page=video&#8221;. The listener for the SWFAddresssEvent.CHANGE in main.swf trigger a function that checks the value of SWFAddress. If the value is &#8220;/NumberOne?page=video&#8221; it dispatches an event using my new custom class from main.swf with an argument (a string).</p>
<p>I also have a listener in the constructor in the document class of numberOne.swf which listens for dispatches through my custom event class and then trigger a function.  This function currently just writes to a Textfield in main.swf but it is meant to load the appropriate movieClips or .swf&#8217;s depending on which argument is passed.</p>
<p>The custom class seem to be set up correctly; I get no errors, and it works as expected if i put the listener and its function inside main.swf. But I get no action when I put the listener inside numberOne.swf. I get the correct SWFAddress-value passed from numberOne.swf to main.swf, but I don&#8217;t get the argument from the custom event class. </p>
<p>Can you see any obvious fault in this outline. The whole thing is laid out on <a href="http://nrksuper.no/superstore/flashfiles/sigtest/dyplenking/" rel="nofollow">http://nrksuper.no/superstore/flashfiles/sigtest/dyplenking/</a> so you can see that it works (somehow) if you like. The file names are in Norwegian so they don&#8217;t totally correspond with the names I&#8217;ve used above.</p>
<p>I hope this isn&#8217;t taking too much of your time</p>
<p>Kind regards<br />
Sigmund Øvrum</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Teal</title>
		<link>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3088</link>
		<dc:creator>John Teal</dc:creator>
		<pubDate>Fri, 05 Jun 2009 18:27:35 +0000</pubDate>
		<guid>http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/#comment-3088</guid>
		<description>Rich –

Regarding my May 21st, 2009 comment (see above);  after much thrashing about, I've come to the conclusion that trying to recreate my old AS2 OOP architecture was the wrong approach--specifically, how I pass events and data (arrays &#38; objects, mostly) between classes. Better is to let AS3 do its thing in its own way. The better solution I’ve come to is to simply use getters &#38; setters in conjunction with standard and custom events. Learning both AS3 and OOP at the same time has been a challenge but, now well along, I find it easier than I expected (hindsight seems to work that way). Your book, and your additional postings here, have provided me with a great AS3 jumpstart and continued resource without which I would not be where I am today. 

Thanks again.</description>
		<content:encoded><![CDATA[<p>Rich –</p>
<p>Regarding my May 21st, 2009 comment (see above);  after much thrashing about, I&#8217;ve come to the conclusion that trying to recreate my old AS2 OOP architecture was the wrong approach&#8211;specifically, how I pass events and data (arrays &amp; objects, mostly) between classes. Better is to let AS3 do its thing in its own way. The better solution I’ve come to is to simply use getters &amp; setters in conjunction with standard and custom events. Learning both AS3 and OOP at the same time has been a challenge but, now well along, I find it easier than I expected (hindsight seems to work that way). Your book, and your additional postings here, have provided me with a great AS3 jumpstart and continued resource without which I would not be where I am today. </p>
<p>Thanks again.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
