<?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: addEventListener using a for loop</title>
	<atom:link href="http://simplistika.com/addeventlistener-using-for-loop/feed/" rel="self" type="application/rss+xml" />
	<link>http://simplistika.com/addeventlistener-using-for-loop/</link>
	<description>Think Simple</description>
	<lastBuildDate>Wed, 07 Jul 2010 22:23:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: jared</title>
		<link>http://simplistika.com/addeventlistener-using-for-loop/comment-page-1/#comment-218</link>
		<dc:creator>jared</dc:creator>
		<pubDate>Sun, 21 Jun 2009 09:19:24 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=205#comment-218</guid>
		<description>if you really want to do it your way, you could store your function names as an Array and access it through there..</description>
		<content:encoded><![CDATA[<p>if you really want to do it your way, you could store your function names as an Array and access it through there..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jared</title>
		<link>http://simplistika.com/addeventlistener-using-for-loop/comment-page-1/#comment-217</link>
		<dc:creator>jared</dc:creator>
		<pubDate>Sun, 21 Jun 2009 09:18:29 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=205#comment-217</guid>
		<description>you&#039;re better off with a stage.addEventListener and in the function, do a switch statement,

switch (e.target.name)
{
case &quot;btn1&quot;:
    // something1
    return;
case &quot;btn2&quot;:
    // something2
    return;
}</description>
		<content:encoded><![CDATA[<p>you&#8217;re better off with a stage.addEventListener and in the function, do a switch statement,</p>
<p>switch (e.target.name)<br />
{<br />
case &#8220;btn1&#8243;:<br />
    // something1<br />
    return;<br />
case &#8220;btn2&#8243;:<br />
    // something2<br />
    return;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kornesh</title>
		<link>http://simplistika.com/addeventlistener-using-for-loop/comment-page-1/#comment-219</link>
		<dc:creator>kornesh</dc:creator>
		<pubDate>Wed, 17 Jun 2009 07:57:30 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=205#comment-219</guid>
		<description>this a sample code that im currently using...but i need to find a way do this long script, as simple as possible...

Code:
btn1.addEventListener(MouseEvent.CLICK, goto1)
btn2.addEventListener(MouseEvent.CLICK, goto2)
btn3.addEventListener(MouseEvent.CLICK, goto3)
btn4.addEventListener(MouseEvent.CLICK, goto4)
btn5.addEventListener(MouseEvent.CLICK, goto5)
different buttons have different functions, so how can i add the functions by looping them?

like....
for (var i:uint = 0; i &lt; 5; i++)
    this[&quot;btn&quot;+i].addEventListener(MouseEvent.MOUSE_OVER, doSomethingDifferent)

how doSomethingDifferent can be manipulated just like the this[&quot;btn&quot;+i], unfortunatlly i cant...it throws error(s)

thanks in advance.</description>
		<content:encoded><![CDATA[<p>this a sample code that im currently using&#8230;but i need to find a way do this long script, as simple as possible&#8230;</p>
<p>Code:<br />
btn1.addEventListener(MouseEvent.CLICK, goto1)<br />
btn2.addEventListener(MouseEvent.CLICK, goto2)<br />
btn3.addEventListener(MouseEvent.CLICK, goto3)<br />
btn4.addEventListener(MouseEvent.CLICK, goto4)<br />
btn5.addEventListener(MouseEvent.CLICK, goto5)<br />
different buttons have different functions, so how can i add the functions by looping them?</p>
<p>like&#8230;.<br />
for (var i:uint = 0; i &lt; 5; i++)<br />
    this[&quot;btn&quot;+i].addEventListener(MouseEvent.MOUSE_OVER, doSomethingDifferent)</p>
<p>how doSomethingDifferent can be manipulated just like the this[&quot;btn&quot;+i], unfortunatlly i cant&#8230;it throws error(s)</p>
<p>thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jared</title>
		<link>http://simplistika.com/addeventlistener-using-for-loop/comment-page-1/#comment-216</link>
		<dc:creator>jared</dc:creator>
		<pubDate>Thu, 19 Feb 2009 02:00:51 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=205#comment-216</guid>
		<description>thanks very helpful!</description>
		<content:encoded><![CDATA[<p>thanks very helpful!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TamaraJane.</title>
		<link>http://simplistika.com/addeventlistener-using-for-loop/comment-page-1/#comment-215</link>
		<dc:creator>TamaraJane.</dc:creator>
		<pubDate>Thu, 19 Feb 2009 01:53:04 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=205#comment-215</guid>
		<description>Oops, I spotted an error which was causing the second function to not get called.

At:
        bams2[i] = new MovieMaterial(getChildByName(&quot;face&quot;+i));
	bams2[i].smooth = true;
	bams[i].interactive = true;

The last line is missing a &#039;2&#039;, it should be
       bams2[i].interactive = true;


Also worth noteing, it seems there are a lot out there interested in sending parameters to functions when adding Listeners.  Some have created separate classes to do this, but I came across this, which works fine:

stage.addEventListener(MouseEvent.CLICK,function(evt:MouseEvent){myfunction(evt,&quot;hello world&quot;)},false , 0 , false);

function myfunction(e:MouseEvent, msg:String):void
{
	trace(msg);
}

traces &quot;Hello World&quot;

Hope that helps someone.</description>
		<content:encoded><![CDATA[<p>Oops, I spotted an error which was causing the second function to not get called.</p>
<p>At:<br />
        bams2[i] = new MovieMaterial(getChildByName(&#8220;face&#8221;+i));<br />
	bams2[i].smooth = true;<br />
	bams[i].interactive = true;</p>
<p>The last line is missing a &#8216;2&#8242;, it should be<br />
       bams2[i].interactive = true;</p>
<p>Also worth noteing, it seems there are a lot out there interested in sending parameters to functions when adding Listeners.  Some have created separate classes to do this, but I came across this, which works fine:</p>
<p>stage.addEventListener(MouseEvent.CLICK,function(evt:MouseEvent){myfunction(evt,&#8221;hello world&#8221;)},false , 0 , false);</p>
<p>function myfunction(e:MouseEvent, msg:String):void<br />
{<br />
	trace(msg);<br />
}</p>
<p>traces &#8220;Hello World&#8221;</p>
<p>Hope that helps someone.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TamaraJane.</title>
		<link>http://simplistika.com/addeventlistener-using-for-loop/comment-page-1/#comment-214</link>
		<dc:creator>TamaraJane.</dc:creator>
		<pubDate>Thu, 19 Feb 2009 01:26:02 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=205#comment-214</guid>
		<description>Thanks for that.
sure.

I decided to remove the parameters though and simply give the movie clip the properties instead, which the function accesses using &#039;target.propertyname&#039;.  K, so this is a bit intertwined with papervision3D (It displays 3 planes, which flip when you clip them):

//imports

var viewport:Viewport3D = new Viewport3D(0, 0, true, true, true, true);
addChild(viewport);
viewport.buttonMode = true;

var renderer:BasicRenderEngine = new BasicRenderEngine();

var scene:Scene3D = new Scene3D();

var camera:Camera3D = new Camera3D();
camera.zoom = 11;
camera.focus = 100;

//positioning of planes
var xpos:Number = 0;
var ypos:Number = 0;

var planesf1:Array = new Array(); //front side of plane
var planesf2:Array = new Array(); //backside of each plane
var bams:Array = new Array(); //font side material
var bams2:Array = new Array(); // back side material

for(var i:uint = 1;i&lt;=3;i++)
{
	bams[i] = new MovieMaterial(getChildByName(&quot;faceb&quot;+i));
	bams[i].interactive = true;
	bams[i].smooth = true;

	bams2[i] = new MovieMaterial(getChildByName(&quot;face&quot;+i));
	bams2[i].smooth = true;
	bams[i].interactive = true;

	this[&quot;faceb&quot;+i].num = i; //property added to movieclip instad of sending parameters
	this[&quot;face&quot;+i].num = i;

	this[&quot;faceb&quot;+i].addEventListener(MouseEvent.CLICK, cardClick); // this listener works fine

	this[&quot;face&quot;+i].addEventListener(MouseEvent.CLICK, cardClick2); //this listener doesn&#039;t seem to get written ??

	planesf1[i] = new Plane(bams[i], 237 , 149 , xpos , ypos);
	planesf1[i].y = ypos;
	planesf1[i].z = 1;

	planesf2[i] = new Plane(bams2[i], 237 , 149 , xpos , ypos);
	planesf2[i].y = ypos;
	planesf2[i].rotationX = 180;
	planesf2[i].z = 0;

	scene.addChild(planesf1[i]);
	scene.addChild(planesf2[i]);
	ypos = ypos + 159;
}

renderer.renderScene(scene , camera , viewport);

function cardClick(e:MouseEvent):void
{
	var i:Number = e.target.num;
	var rot:Number = planesf1[i].rotationY + 180;
	Tweener.addTween(planesf1[i], { time:2, transition:&#039;easeinoutback&#039;, rotationY: rot } );
	var rot2:Number = planesf2[i].rotationY + 180;
	Tweener.addTween(planesf2[i], { time:2, transition:&#039;easeinoutback&#039;, rotationY: rot2 } );

}

function cardClick2(e:MouseEvent):void
{
	trace(e.target.num);
	var j:Number = e.target.num;
	var rot3:Number = planesf1[j].rotationY + 180;
	Tweener.addTween(planesf1[j], { time:2, transition:&#039;easeinoutback&#039;, rotationY: rot3 } );
	var rot4:Number = planesf2[j].rotationY + 180;
	Tweener.addTween(planesf2[j], { time:2, transition:&#039;easeinoutback&#039;, rotationY: rot4 } );

}

addEventListener(Event.ENTER_FRAME, loop);

function loop(e:Event):void
{
	   renderer.renderScene(scene, camera, viewport);
}</description>
		<content:encoded><![CDATA[<p>Thanks for that.<br />
sure.</p>
<p>I decided to remove the parameters though and simply give the movie clip the properties instead, which the function accesses using &#8216;target.propertyname&#8217;.  K, so this is a bit intertwined with papervision3D (It displays 3 planes, which flip when you clip them):</p>
<p>//imports</p>
<p>var viewport:Viewport3D = new Viewport3D(0, 0, true, true, true, true);<br />
addChild(viewport);<br />
viewport.buttonMode = true;</p>
<p>var renderer:BasicRenderEngine = new BasicRenderEngine();</p>
<p>var scene:Scene3D = new Scene3D();</p>
<p>var camera:Camera3D = new Camera3D();<br />
camera.zoom = 11;<br />
camera.focus = 100;</p>
<p>//positioning of planes<br />
var xpos:Number = 0;<br />
var ypos:Number = 0;</p>
<p>var planesf1:Array = new Array(); //front side of plane<br />
var planesf2:Array = new Array(); //backside of each plane<br />
var bams:Array = new Array(); //font side material<br />
var bams2:Array = new Array(); // back side material</p>
<p>for(var i:uint = 1;i&lt;=3;i++)<br />
{<br />
	bams[i] = new MovieMaterial(getChildByName(&#8220;faceb&#8221;+i));<br />
	bams[i].interactive = true;<br />
	bams[i].smooth = true;</p>
<p>	bams2[i] = new MovieMaterial(getChildByName(&#8220;face&#8221;+i));<br />
	bams2[i].smooth = true;<br />
	bams[i].interactive = true;</p>
<p>	this["faceb"+i].num = i; //property added to movieclip instad of sending parameters<br />
	this["face"+i].num = i;</p>
<p>	this["faceb"+i].addEventListener(MouseEvent.CLICK, cardClick); // this listener works fine</p>
<p>	this["face"+i].addEventListener(MouseEvent.CLICK, cardClick2); //this listener doesn&#8217;t seem to get written ??</p>
<p>	planesf1[i] = new Plane(bams[i], 237 , 149 , xpos , ypos);<br />
	planesf1[i].y = ypos;<br />
	planesf1[i].z = 1;</p>
<p>	planesf2[i] = new Plane(bams2[i], 237 , 149 , xpos , ypos);<br />
	planesf2[i].y = ypos;<br />
	planesf2[i].rotationX = 180;<br />
	planesf2[i].z = 0;</p>
<p>	scene.addChild(planesf1[i]);<br />
	scene.addChild(planesf2[i]);<br />
	ypos = ypos + 159;<br />
}</p>
<p>renderer.renderScene(scene , camera , viewport);</p>
<p>function cardClick(e:MouseEvent):void<br />
{<br />
	var i:Number = e.target.num;<br />
	var rot:Number = planesf1[i].rotationY + 180;<br />
	Tweener.addTween(planesf1[i], { time:2, transition:&#8217;easeinoutback&#8217;, rotationY: rot } );<br />
	var rot2:Number = planesf2[i].rotationY + 180;<br />
	Tweener.addTween(planesf2[i], { time:2, transition:&#8217;easeinoutback&#8217;, rotationY: rot2 } );</p>
<p>}</p>
<p>function cardClick2(e:MouseEvent):void<br />
{<br />
	trace(e.target.num);<br />
	var j:Number = e.target.num;<br />
	var rot3:Number = planesf1[j].rotationY + 180;<br />
	Tweener.addTween(planesf1[j], { time:2, transition:&#8217;easeinoutback&#8217;, rotationY: rot3 } );<br />
	var rot4:Number = planesf2[j].rotationY + 180;<br />
	Tweener.addTween(planesf2[j], { time:2, transition:&#8217;easeinoutback&#8217;, rotationY: rot4 } );</p>
<p>}</p>
<p>addEventListener(Event.ENTER_FRAME, loop);</p>
<p>function loop(e:Event):void<br />
{<br />
	   renderer.renderScene(scene, camera, viewport);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jared</title>
		<link>http://simplistika.com/addeventlistener-using-for-loop/comment-page-1/#comment-213</link>
		<dc:creator>jared</dc:creator>
		<pubDate>Thu, 19 Feb 2009 00:53:52 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=205#comment-213</guid>
		<description>woops. fixed now. care to share your code as well.</description>
		<content:encoded><![CDATA[<p>woops. fixed now. care to share your code as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TamaraJane.</title>
		<link>http://simplistika.com/addeventlistener-using-for-loop/comment-page-1/#comment-212</link>
		<dc:creator>TamaraJane.</dc:creator>
		<pubDate>Thu, 19 Feb 2009 00:49:49 +0000</pubDate>
		<guid isPermaLink="false">http://jared.simplistika.com/?p=205#comment-212</guid>
		<description>heya, very handy, I&#039;m implementing something similar except that the method I call sends a couple of parameters as well. Having trouble though and was keen to see your source code but the link doesn&#039;t work to

&quot;Click here to download sample file addEventListener.fla&quot;

Cheers</description>
		<content:encoded><![CDATA[<p>heya, very handy, I&#8217;m implementing something similar except that the method I call sends a couple of parameters as well. Having trouble though and was keen to see your source code but the link doesn&#8217;t work to</p>
<p>&#8220;Click here to download sample file addEventListener.fla&#8221;</p>
<p>Cheers</p>
]]></content:encoded>
	</item>
</channel>
</rss>
