<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://eduncan911.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Eric Duncan : Computer Programming, Flash</title><link>http://eduncan911.com/archive/tags/Computer+Programming/Flash/default.aspx</link><description>Tags: Computer Programming, Flash</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Dynamic Instance Names of TextFields - A work around</title><link>http://eduncan911.com/blog/dynamic-instance-names-of-textfields-a-work-around.aspx</link><pubDate>Wed, 07 Mar 2007 20:08:00 GMT</pubDate><guid isPermaLink="false">3cbf8099-f611-4197-a0f5-c5a9f8954971:5694</guid><dc:creator>Eric A. Duncan</dc:creator><slash:comments>1</slash:comments><comments>http://eduncan911.com/comments/5694.aspx</comments><wfw:commentRss>http://eduncan911.com/commentrss.aspx?PostID=5694</wfw:commentRss><description>&lt;P&gt;As I am starting to get back into heavy Flash development&amp;nbsp;after my 5+ year hiatus, I see that Macromedia has added quite a lot of interesting concepts to the newer versions of ActionScript.&lt;/P&gt;
&lt;P&gt;But the purpose of this post is to outline that Macromedia (err now Adobe) still has a lot of work to do on their ActionScript engine, specifically with Dynamic Instance naming conventions (and new-object intellisense would really be nice by now, after all of these years).&amp;nbsp;&amp;nbsp;I am assuming you know flash, a little bit.&amp;nbsp; At least to the level of knowing that you need set an InstanceName of a Symbol, in order to be able to edit its properties at runtime.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;I just spent too much time today trying to figure out why my code wasn't working.&amp;nbsp; I am creating numerous dynamic TextFields, but I need to be able to access them for updates in code.&amp;nbsp; And to complicate things, the TextFields will be loaded from different XML files - meaning they will have different InstanceNames.&lt;/P&gt;
&lt;P&gt;You usually can create a dynamic instance name by using the old-school method of&amp;nbsp;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;"&gt;hardCodedName[variable]&lt;/SPAN&gt; or the even older&amp;nbsp;&lt;SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;"&gt;eval("hardCodedName" + variable)&lt;/SPAN&gt; method.&amp;nbsp; For example, say I want to create a new movie into a dynamic variable made up of an integer I have in a for i++ loop:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;for (int i = 0; i &amp;lt; total; i++)
{
  loadMovie( "myMovie" + i + ".swf", _root.myMovie[ i ] );
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or...&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;for (int i = 0; i &amp;lt; total; i++)
{
  loadMovie( "myMovie" + i + ".swf", _root.eval("myMovie" + i) );
}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Both of these examples should result in loading myMovie0.swf into the dynamic variable name of /level0/myMovie0 (or _root.myMovie0 per dot-syntax).&amp;nbsp; &lt;/P&gt;
&lt;P&gt;What&amp;nbsp;I found today is that when using some of the newer ActionScript 2.0 and 3.0 functions, they do not honor these methods completely.&amp;nbsp; I had to use a mixture of the two examples above to get it work, and actually could not use either method when creating the object!&amp;nbsp; This is the craziest thing I've seen to where eval() works in referencing the object, but does not work in the creation of the object.&amp;nbsp; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;var _root.totalCount:Number = 0;
function CreateMenuItem(Text:String, Href:String, Title:String, Spacer:Boolean)
{
    // create the symbol at the last Y position we are tracking
    this.createTextField("movFlyoutText" + _root.totalCount
        , _root.totalCount, _root.textXpos, _root.lastYpos, _root.textWidth, _root.textHeight);
    eval("movFlyoutText" + _root.totalCount).wordWrap = true;
    eval("movFlyoutText" + _root.totalCount).multiline = true;
    eval("movFlyoutText" + _root.totalCount).border = false;
    eval("movFlyoutText" + _root.totalCount).type = "dynamic";
    eval("movFlyoutText" + _root.totalCount).antiAliasType = "advanced";
    
    textFormat = new TextFormat();
    textFormat.color = 0xffffff;
    textFormat.size = 12;
    textFormat.font = "Futura Condensed";
    
    if (Spacer != true)
    {
      formatText.url = Href;
    }
    
    if (Text.length &amp;gt; 0)
    {
        eval("movFlyoutText" +  _root.totalCount).text = Text;
    }
    else
    {
        eval("movFlyoutText" + _root.totalCount).text = " ";
    }
    
    eval("movFlyoutText" + _root.totalCount).setTextFormat(textFormat);
    
    // reset some vars
    var tmp:Number = eval("movFlyoutText" + _root.totalCount)._height;
    _root.lastYpos = _root.lastYpos + tmp;
    
    _root.totalCount++;
}

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Above is the code I wrote today, to where I can not use [] reference or the eval() reference to get the TextField created properly using the newer &lt;SPAN style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:10pt;"&gt;createTextField&lt;/SPAN&gt;method.&amp;nbsp; But in other methods throughout my code, using the [] reference works at the baseline.&amp;nbsp; Go figure.&lt;/P&gt;
&lt;P&gt;And as mentioned above, I can not use brackets[] when referencing the object either to set its properties!&amp;nbsp; I had to use eval().&amp;nbsp; Man, how ugly is this code?&amp;nbsp; I'm open to other suggestions.&lt;/P&gt; &lt;img src="http://eduncan911.com/aggbug.aspx?PostID=5694" width="1" height="1"&gt;</description><category domain="http://eduncan911.com/archive/tags/Geek+Stuff/default.aspx">Geek Stuff</category><category domain="http://eduncan911.com/archive/tags/Computer+Programming/default.aspx">Computer Programming</category><category domain="http://eduncan911.com/archive/tags/Flash/default.aspx">Flash</category></item></channel></rss>