Almost right kglad .. but it has nothing to do with whether the string names
an object or not.
The 'this[xxx]' notation will give you the value of a named property or
non-local variable, where xxx evaluates to the name or the property or
variable. Doesn't matter whether it is an object or not. Similar for
variations like '_root[xxx]' or 'myclip[xxx]' .. the difference being where
it looks for the property/variable (ie look in this, or _root, or myclip
etc). It will not give you the values of local variables (even if there is
a local variable with that name)
'eval(xxx)' will give you variables or properties .. but unlike the explicit
'this[xxx]', it will always look first in any 'with' context, next in any
local variables (which you cannot get at via the 'this[xxx]' notation), and
then in the _target for the code (which is not necessarily the same as the
'this' object) and finally in the _global object. It will not look at the
'this' object at all (unless the current _target and 'this' happen to be the
same).
So they are quite different in the way they work .. but not in the way kglad
explains.
Here is an example (assuming you have a movie clip called 'myclip')
_global.yyy = "yyy global";
xxx = "xxx in scene";
myclip.xxx = "xxx in myclip";
myclip.f = function() {
trace("this['xxx']="+this['xxx']); // displays "this['xxx']=xxx in
myclip"
trace("eval('xxx')="+eval('xxx')); // displays "eval('xxx')=xxx in scene"
var xxx = "xxx local var";
trace("eval('xxx')="+eval('xxx')); // display "eval('xxx')=xxx local var"
with (myclip) {
trace("eval('xxx')="+eval('xxx')); // display "eval('xxx')=xxx in
myclip"
trace("eval('yyy')="+eval('yyy')); // display "eval('yyy')=yyy global"
}
}
myclip.f();
notice how the results are different. This is NOT to do with whether the
value of variable 'xxx' is an object or a string etc.
[quoted text, click to view] "kglad" <webforumsuser@macromedia.com> wrote in message
news:cjvidd$pjg$1@forums.macromedia.com...
> to resolve a string to an object use bracket notation.
> for example:
>
> myObject=new Object();
> myString="myObject";
> // this[myString] will resolve to myObject
>
> and to resolve a string to a variable use the eval() function. for
> example:
>
> myVar=3.14159;
> myString="myVar";
> // eval(myString) will resolve to myVar.
>