Difference between eval () and _root[]?

Well, the title says it all.\r\rThe thing is : I never got that eval () function to work. I’ve seen it quite a couple of times in fla though, but whenever I want to use it, it just won’t work.\r\rThanks\r\rpom 0]

I’d tell you but I didn’t bring that book with me. To tell the truth, I’ve only used it a couple of times as well, just because it seems to be tricky somehow. At least, I’m not doing something right with it either, but I’ve gotten it to work a couple times.\r\r_root[] is another matter and I really don’t know why you’re comparing the two. Unless I’m misunderstanding what you’re asking.\r\rI would use it in a case like this.\r\rfor(i=0,i<200,i++){\r_root[“myVariable”+i]._x=something+i;\r}\r\rthis is where I need to call to change the property of a series of movie clips with nearly identical names. since you can’t use quotations inside a call function like that… you have to use brackets to saround the information. The biggest mistake I make with this is forgetting wether the “.” in front of the brackets is left out, or after them.

Well, I don’t know, I thought that eval(“thing”+i) was doing thingi, but obviously I’m mistaken…\r\rpom 0]

eval returns whats inside a variable, else you don’t get the content, you get only the var’s name!

for (x = 0; x < 10; ++x) {\rtrace(eval(“test”+x));\r}\r//output:\r\rtest0\rtest1\rtest2\rtest3\rtest4\rtest5\rtest6\rtest7\rtest8\rtest9\r\ryou also mentioned “_root[]”. now you could achieve the same thing above without the “eval” function. but you can’t simply do:\r"test"+x;\ryou have to let flash know where this variable (or movieinstance name) is. that is where “_root[]” comes in. say all the variables were on the root. you can call them each like so:\r\rfor (x = 0; x < 10; ++x) {\rtrace(_root[“test”+x]);\r}\r\rthis would output the values in those 9 varibles.\rnow if the vars weren’t in the root, like say, in a movieclip, you would call them like so:\r\rfor (x = 0; x < 10; ++x) {\rtrace(this[“test”+x]);\r}\r\rnotice in the previous two examples i didn’t use eval, when you use bracket notation ("[ ]") you don’t need it. eval is sorta like the same thing. \rhope this helped.

cool… I never knew that… :slight_smile:

They don’t seem to be interchangeable though. I mean, I don’t think you can do :

 movie = eval("copy"+i) ;\r\r_root.movie._x = 50 ;

Can you ?? I have to try that…\r\rpom 0]

actually, you can, i do it all the time. saves me a lot of typing.\reg:\r\rmc = _root[“copy”+x];\rmc._x = random(550);\r…

Dammit, it works…\rOK, thanks Thor.\r\rpom 0]