Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eval behaviour in Flash 5

Status
Not open for further replies.

sphinx54

Programmer
Nov 6, 2001
1
CA
I'm trying to generate a menu dynamically based on an XML file. To do this I have several textboxes which I have enumerated as button0caption, button1caption, etc. My question is in two parts:

1. Can I make an array of textboxes somehow so that I can refer to them as buttoncaption[0], buttoncaption[1]? Does naming two textboxes "buttoncaption" accomplish this?

2. If option 1 is infeasible, can I use the eval command to loop through the textboxes? I'm a veteran Javascript programmer and in Javascript eval seems to behave differently than in ActionScript.

For example, in Javascript I would use:
Code:
eval("button" + 0 + "caption = 'something'");
to accomplish:
Code:
button0caption = 'something';

In ActionScript this does not seem to work.

Thanks very much for your help.
 
Eval does work slightly differently in ActionScript but it should still give you what you need. For instance you could loop through a bunch of movieclips and set properties like this...

for (i=1;i<10;i++){
eval(&quot;movieClip&quot;+i)._alpha=10*i;
}

this would also work...

for (i=1;i<10;i++){
eval(&quot;movie&quot; + &quot;Clip&quot;+i)._alpha=10*i;
}

Dumb example but it gives you the syntax :).

An alternative format is this...

for (i=1;i<10;i++){
_root[&quot;movieClip&quot;+i]._alpha=10*i;
}

You can use arrays to access movieClip properties also it depends whether the &quot;buttonCaptions&quot; you talk about are variables that you've set the textboxes to or are they actual movieClips that contain textboxes? If you go the movieClip route you should be able to get the results you're after.

 
shouldn't you be trying to achieve button0.caption=&quot;something&quot;

foo = eval(&quot;button&quot; + number);
foo.caption = &quot;something&quot;;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top