all groups > flash actionscript > october 2004 >
You're in the

flash actionscript

group:

StringTokenizer and StringtoValue


StringTokenizer and StringtoValue freez
10/5/2004 7:47:26 PM
flash actionscript:
Hi,

Is there a funktion like StringTokenizer and StringtoValue in Flash,
like in Java?

Thanx freez
Re: StringTokenizer and StringtoValue kglad
10/6/2004 1:39:57 AM
not exactly. flash does have ways to resolve a string into an object and a
string into a variable. 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.
Re: StringTokenizer and StringtoValue Jeckyl
10/6/2004 12:04:34 PM
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]

AddThis Social Bookmark Button