A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: What's wrong with this code?

  1. #1
    Senior Member
    Join Date
    Jul 2001
    Posts
    235

    What's wrong with this code?

    for (i=0;i<6;i++){
    eval("newposition"+i) = eval("_rootosition"+i)
    }

    I am trying to create a variable and add "i" so that I don't have to write it out 6 times.

    It keeps giving me this error message:

    Symbol=controller, Layer=Layer 1, Frame=2: Line 3: Left side of assignment operator must be variable or property.
    eval("newposition"+i) = eval("_rootosition"+i)


    Isn't it a variable?

    I'm just not great at hardcoding (if that's what you call it).

    Appreciate any help

  2. #2
    FK Slacker
    Join Date
    Jun 2000
    Location
    vancouver
    Posts
    3,208
    Try:
    code:

    for (i=0;i<6;i++){
    this["newposition"+i]=_root["position"+i];
    }



    K.

  3. #3
    Senior Member
    Join Date
    Oct 2004
    Posts
    134
    try this:
    code:

    for(var i = 0; i < 6; i++){
    _root["newposition" + i] = _root["position" + i];
    }


    oops, too late, hehe

  4. #4
    Senior Member
    Join Date
    Jul 2001
    Posts
    235
    Thanks for the replies.

    I just want to understand, what is the difference between the square brackets from the normal or curly?

    Also, I am trying to implement it to a property but it doesn't work. Any suggestions on the following?:

    _root["box" + i + "._x"] = (this["newposition"+i]+(_root["box"+i+"._x"])) + 2;

  5. #5
    Senior Member
    Join Date
    Oct 2004
    Posts
    134
    [] = an array
    all the items on the root timeline are stored as an array.
    and your line should read:
    Code:
    _root["box" + i]._x = this["newposition" + i] + _root["box" + i]._x + 2;

  6. #6
    Senior Member
    Join Date
    Jul 2001
    Posts
    235
    Thanks, that worked perfect!

  7. #7
    Senior Member
    Join Date
    Oct 2004
    Posts
    134
    yw

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