dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: problem with eval

  1. #1
    Senior Member maksum's Avatar
    Join Date
    Oct 2002
    Location
    Portland, OR
    Posts
    118

    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.

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    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

  3. #3
    Senior Member maksum's Avatar
    Join Date
    Oct 2002
    Location
    Portland, OR
    Posts
    118
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center