-
Senior Member
problem with eval
Can someone explain to me why I'm getting an error here? The problem I'm ultimately trying to solve is much larger and more complex, but I have reduced the specific problem I'm having can be reduced to this I believe:
//EXAMPLE ONE
var myVar = null;
_root.myVar = 1;
trace(_root.myVar);
//EXAMPLE TWO
var myVar = null;
(eval("_root.myVar")) = 1;
trace(_root.myVar);
//EXAMPLE TWO generates error:
//Left side of assignment operator must be variable or property.
-
Senior Member
I don't think you can assign a value to the result of an eval statement, you should use array syntax instead,
for example,
_root["myVar"] = 1; // _root.myVar = 1
i = 1;
_root["myVar" + i] = 1; // _root.myVar1 = 1
-
Senior Member
Wow, I never knew you could do that. That works precisely how I needed it to. Thank you VERY much for sharing your expertise. I appreciate it!
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|