

<?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: How to Reference Objects Dynamically</title>
	<atom:link href="http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically/feed" rel="self" type="application/rss+xml" />
	<link>http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically</link>
	<description>Luck is the residue of good design.</description>
	<lastBuildDate>Tue, 20 Mar 2012 15:33:23 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: nick</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-541453</link>
		<dc:creator>nick</dc:creator>
		<pubDate>Thu, 23 Jun 2011 18:45:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-541453</guid>
		<description>hello,
I am trying to find a way to use eval() to get the name from an array to the variable assigned to a  dynamic text box and then set the :string for that  dynamic text box 

var this[tempLanguage[i]]:String = dataSetLanguage[1][2];

sorry I know I should probably be able to figure out from the information above.</description>
		<content:encoded><![CDATA[<p>hello,<br />
I am trying to find a way to use eval() to get the name from an array to the variable assigned to a  dynamic text box and then set the :string for that  dynamic text box </p>
<p>var this[tempLanguage[i]]:String = dataSetLanguage[1][2];</p>
<p>sorry I know I should probably be able to figure out from the information above.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tiemen</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-179707</link>
		<dc:creator>Tiemen</dc:creator>
		<pubDate>Thu, 08 May 2008 15:04:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-179707</guid>
		<description>Thanks for the reply. I have been doing a LOT of flash lately, making comforting jumps in level, but though I understand what you&#039;re doing, it does not actually make sense. For this example, the variable I want to set is a semi-global one, defined in the main timeline. Flash doesn&#039;t convert the i in the onRelease handler to a static number, which I thought it should when it&#039;s used inside a for loop.

So it writes a handler function like this, which finds when invoked, the out-serviced i variable lying around at 9

d3_mc.onRelease = function() {
    var_num = i;
    trace(i); // traces 9, which makes sense
}

It should&#039;v been this though:

d3_mc.onRelease = function() {
    var_num = 3;
    trace(3);
}

So what you mean by scope, is that &quot;i&quot; cannot be used on the right side of the equation inside a function declaration?</description>
		<content:encoded><![CDATA[<p>Thanks for the reply. I have been doing a LOT of flash lately, making comforting jumps in level, but though I understand what you&#8217;re doing, it does not actually make sense. For this example, the variable I want to set is a semi-global one, defined in the main timeline. Flash doesn&#8217;t convert the i in the onRelease handler to a static number, which I thought it should when it&#8217;s used inside a for loop.</p>
<p>So it writes a handler function like this, which finds when invoked, the out-serviced i variable lying around at 9</p>
<p>d3_mc.onRelease = function() {<br />
    var_num = i;<br />
    trace(i); // traces 9, which makes sense<br />
}</p>
<p>It should&#8217;v been this though:</p>
<p>d3_mc.onRelease = function() {<br />
    var_num = 3;<br />
    trace(3);<br />
}</p>
<p>So what you mean by scope, is that &#8220;i&#8221; cannot be used on the right side of the equation inside a function declaration?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-179156</link>
		<dc:creator>David Stiller</dc:creator>
		<pubDate>Thu, 08 May 2008 04:11:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-179156</guid>
		<description>Tiemen,

I&#039;m going through my notes, man, and I honestly can&#039;t find (i.e., can&#039;t remember) if I replied to you about the &lt;code&gt;Key&lt;/code&gt; event listener.  I hope I did!  I&#039;ve been going insane lately with ridiculous schedule conflicts.

As for the &quot;lazy code&quot; question, I think it&#039;s an issue of scope.  Check out this revision:

&lt;pre&gt;&lt;code&gt;for (var i:Number = 1; i &lt; 9; i++) {
  this[&quot;d&quot; + i + &quot;_mc&quot;].var_num = i;
  this[&quot;d&quot; + i + &quot;_mc&quot;].onRelease = function() {
    trace(this.var_num);
    gotoAndStop(4);
  };
}&lt;/code&lt;/pre&gt;

I resisted the urge to add strong typing.  ;)  But this does what you want.</description>
		<content:encoded><![CDATA[<p>Tiemen,</p>
<p>I&#8217;m going through my notes, man, and I honestly can&#8217;t find (i.e., can&#8217;t remember) if I replied to you about the <code>Key</code> event listener.  I hope I did!  I&#8217;ve been going insane lately with ridiculous schedule conflicts.</p>
<p>As for the &#8220;lazy code&#8221; question, I think it&#8217;s an issue of scope.  Check out this revision:</p>
<pre><code>for (var i:Number = 1; i < 9; i++) {
  this["d" + i + "_mc"].var_num = i;
  this["d" + i + "_mc"].onRelease = function() {
    trace(this.var_num);
    gotoAndStop(4);
  };
}</code</pre>
<p>I resisted the urge to add strong typing.  <img src='http://www.quip.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   But this does what you want.</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tiemen</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-172288</link>
		<dc:creator>Tiemen</dc:creator>
		<pubDate>Tue, 29 Apr 2008 23:33:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-172288</guid>
		<description>well, trust me that the for loop is correct, for i iterates over 8.</description>
		<content:encoded><![CDATA[<p>well, trust me that the for loop is correct, for i iterates over 8.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tiemen</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-172286</link>
		<dc:creator>Tiemen</dc:creator>
		<pubDate>Tue, 29 Apr 2008 23:31:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-172286</guid>
		<description>Hmm here&#039;s me again with a small silly question.

Why won&#039;t this lazy code work?

&lt;pre&gt;&lt;code&gt;for (var i:Number = 1; i
  this[&quot;d&quot;+ i +&quot;_mc&quot;].onRelease = function() {
    var_num = i;
    trace(var_num);
    gotoAndStop(4);
  }
}&lt;/code&gt;&lt;/pre&gt;

Clicking on any of the 8 buttons traces &quot;9&quot;, which pretty much baffles me.</description>
		<content:encoded><![CDATA[<p>Hmm here&#8217;s me again with a small silly question.</p>
<p>Why won&#8217;t this lazy code work?</p>
<pre><code>for (var i:Number = 1; i
  this["d"+ i +"_mc"].onRelease = function() {
    var_num = i;
    trace(var_num);
    gotoAndStop(4);
  }
}</code></pre>
<p>Clicking on any of the 8 buttons traces &#8220;9&#8243;, which pretty much baffles me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tiemen</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-160256</link>
		<dc:creator>Tiemen</dc:creator>
		<pubDate>Thu, 10 Apr 2008 10:31:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-160256</guid>
		<description>Next day I had this solved. I still don&#039;t understand how this works exactly, as there seem many roads that lead to Rome. The one I used in this case with the createEmptyMovieClip was:

&lt;code&gt;reference = this.createEmptyMovieClip(i +&quot;_mc&quot;, this.getNextHighestDepth());&lt;/code&gt;
&lt;code&gt;reference._x = something_crazy;&lt;/code&gt;

But this one has no (obvious) affiliation with any of the methods you mentioned! I couldn&#039;t get a &lt;code&gt;this[]&lt;/code&gt; or &lt;code&gt;eval()&lt;/code&gt; notation to work within a Key. event anyway...?!</description>
		<content:encoded><![CDATA[<p>Next day I had this solved. I still don&#8217;t understand how this works exactly, as there seem many roads that lead to Rome. The one I used in this case with the createEmptyMovieClip was:</p>
<p><code>reference = this.createEmptyMovieClip(i +"_mc", this.getNextHighestDepth());</code><br />
<code>reference._x = something_crazy;</code></p>
<p>But this one has no (obvious) affiliation with any of the methods you mentioned! I couldn&#8217;t get a <code>this[]</code> or <code>eval()</code> notation to work within a Key. event anyway&#8230;?!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tiemen</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-160104</link>
		<dc:creator>Tiemen</dc:creator>
		<pubDate>Thu, 10 Apr 2008 01:37:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-160104</guid>
		<description>Incredible... I&#039;ve been stuck for over two hours now on the dynamic creation of movieclips. For some reason 

&lt;code&gt;for (var i:Number = 0; i&lt;/code&gt; [code snipped by WordPress]

inside a onKeyUp event really doesn&#039;t want to work. Outside the onKeyUp, it does.
It&#039;s driving me crazy...</description>
		<content:encoded><![CDATA[<p>Incredible&#8230; I&#8217;ve been stuck for over two hours now on the dynamic creation of movieclips. For some reason </p>
<p><code>for (var i:Number = 0; i</code> [code snipped by WordPress]</p>
<p>inside a onKeyUp event really doesn't want to work. Outside the onKeyUp, it does.<br />
It's driving me crazy...</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-159054</link>
		<dc:creator>David Stiller</dc:creator>
		<pubDate>Tue, 08 Apr 2008 00:46:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-159054</guid>
		<description>P.J.,

This is an issue of scope.  You&#039;re declaring a variable named &lt;code&gt;token&lt;/code&gt; inside the scope of this function, &lt;code&gt;notify()&lt;/code&gt;, yet in the condition of your &lt;code&gt;if&lt;/code&gt; statement, you&#039;re referencing &lt;code&gt;_root.token&lt;/code&gt; which, contrary to your expectations, is trying to reference a completely different &lt;code&gt;token&lt;/code&gt; variable; namely, the non-existent one scoped to the main timeline (&lt;code&gt;_root&lt;/code&gt;).  Does that make sense?  You&#039;ve got two &lt;code&gt;token&lt;/code&gt; references going, one of which doesn&#039;t exist.  The one you&#039;re referencing in the condition doesn&#039;t exist.

If you want to reference &lt;code&gt;_root&lt;/code&gt; as your container object, I recommend you go with the array access operator instead:

&lt;pre&gt;&lt;code&gt;function notify() {
  for (n=1;n&lt;7;n++) {
    if (_root.jv_mc.hitTest(_root[&quot;tkn&quot; + n]) {
      notice_mc.gotoAndPlay(2);
    }
  }
}&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>P.J.,</p>
<p>This is an issue of scope.  You&#8217;re declaring a variable named <code>token</code> inside the scope of this function, <code>notify()</code>, yet in the condition of your <code>if</code> statement, you&#8217;re referencing <code>_root.token</code> which, contrary to your expectations, is trying to reference a completely different <code>token</code> variable; namely, the non-existent one scoped to the main timeline (<code>_root</code>).  Does that make sense?  You&#8217;ve got two <code>token</code> references going, one of which doesn&#8217;t exist.  The one you&#8217;re referencing in the condition doesn&#8217;t exist.</p>
<p>If you want to reference <code>_root</code> as your container object, I recommend you go with the array access operator instead:</p>
<pre><code>function notify() {
  for (n=1;n&lt;7;n++) {
    if (_root.jv_mc.hitTest(_root[&quot;tkn&quot; + n]) {
      notice_mc.gotoAndPlay(2);
    }
  }
}</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: P.J.</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-152046</link>
		<dc:creator>P.J.</dc:creator>
		<pubDate>Sun, 23 Mar 2008 10:50:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-152046</guid>
		<description>I don&#039;t seem to have any luck getting variables to work. I have six identical movieclips on the stage and I would like to include them all in certain functions/statements. Right now, I had to settle for writing out an identical statement for each instance and that works fine. But it&#039;s very time consuming, especially for more complex if/else statements, and the resulting code is very unwieldy to say the least.

So if the movieclips are named tkn1 through tkn6 and I want to execute a certain code whenever any of these clips are intersecting with a movieclip named jv_mc, I tried the following and it did nothing.

&lt;pre&gt;&lt;code&gt;function notify() {
  var token:MovieClip;
  for (n=1;n&lt;7;n++) {
    token = eval(&quot;tkn&quot;+n)
    //the condition/statement
    if (_root.jv_mc.hitTest(_root.token)) {
      notice_mc.gotoAndPlay(2);
    }
  }
}&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I don&#8217;t seem to have any luck getting variables to work. I have six identical movieclips on the stage and I would like to include them all in certain functions/statements. Right now, I had to settle for writing out an identical statement for each instance and that works fine. But it&#8217;s very time consuming, especially for more complex if/else statements, and the resulting code is very unwieldy to say the least.</p>
<p>So if the movieclips are named tkn1 through tkn6 and I want to execute a certain code whenever any of these clips are intersecting with a movieclip named jv_mc, I tried the following and it did nothing.</p>
<pre><code>function notify() {
  var token:MovieClip;
  for (n=1;n&lt;7;n++) {
    token = eval("tkn"+n)
    //the condition/statement
    if (_root.jv_mc.hitTest(_root.token)) {
      notice_mc.gotoAndPlay(2);
    }
  }
}</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Stiller</title>
		<link>http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-120721</link>
		<dc:creator>David Stiller</dc:creator>
		<pubDate>Tue, 15 Jan 2008 02:15:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically#comment-120721</guid>
		<description>Billy,

Glad to help!  :)</description>
		<content:encoded><![CDATA[<p>Billy,</p>
<p>Glad to help!  <img src='http://www.quip.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

