PDA

View Full Version : Using a variable in a path?



CoDe-ReD
October 15th, 2007, 09:02 AM
Hi people,

I'm currently kinda stuck on an app Im developing.

I want to use a variable within a path.

Lets say my var's name is "i" and it consists of a number that will be changed.

So its basically var i = 0 and in a loop it says i++

Now I want to target this var in a path.

Lets say app."textfield"+i.text = "test"

That actionscript is wrong, but it's there to give you an idea of what I'm trying to accomplish.

So basically: how do I target an object with a variable path?

dewey
October 15th, 2007, 10:31 AM
Hi CoDe

I just had a similar issue and used the getChildByName("clipname" + i) type approach...

Hope this helps...

CoDe-ReD
October 15th, 2007, 02:53 PM
Hmm Im not sure what you mean. Can you please explain to me a bit more how you used it?

Thnx a lot :)

brianmanden
October 15th, 2007, 05:43 PM
try



myTemp = eval("string"+i);
myTemp.text="anotherString;"


or



someHolder.["string"+i]text="anotherString;"

dstanford
October 17th, 2007, 06:26 PM
I have this same problem and I don't feel like anyone has given a good answer so far that will work in AS 3.0. This was so easy in AS 2.0. All you had to do was something like this:

for (i=0; i < 10; i++) {
this["myTextField"+i].text = arrayOfText[i];
}

(Or you could use _root instead of this, if your text field was at the root level.)

Now in 3.0, nothing I try works. All my attempts to use the square-bracket syntax in the path to the text field generate errors, creating a temp. holder variable to hold the name of the text field instance for a sec doesn't work...it's really frustrating. Surely there has to be a simple way to write a path in which the instance name you're targeting is provided by concatenating a string and a loop's iteration variable.