A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [MX] set("a"+i+"._x","b"+i+"._x") help.

  1. #1
    Member
    Join Date
    Nov 2006
    Posts
    69

    [MX] set("a"+i+"._x","b"+i+"._x") help.

    As you can probably see by the title, I want to address the x of one to the x of another, the problem being that they are both dynamically named and called.

    If I write
    set("whatever"+i+"._x",400); // x goes to 400 no problems.

    However if I write
    set("whatever"+i+"._x","object"+i+"._x"); // it asumes that the second variable is just a string value and not the thing I want to call.

    Can someone tell me how to set a1._x to b1._x dynamically, (preferably in a similar way to described above.)

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe try something like this...

    Code:
    whatever = "a";
    otherone = "b";
    i = 1;
    eval(whatever + i)._x = eval(otherone + i)._x;

  3. #3
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    mess with this:
    code:

    var x;
    var y = 12;
    var myX12 = 7;
    var mySpot = eval("myX"+y);
    set('x',mySpot);
    trace('x: '+ x);
    stop();



    i would take: object"+i+"._x and do this
    var myNewObject = eval("object"+i+"._x");
    set("whatever"+i+"._x",myNewObject); // no quotes

    hope this helps

    IMS

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    use array notation and dot notation , (don't use set, that's old school) e.g

    Code:
    this["whatever"+i]._x = this["object"+i]._x;
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  5. #5
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    silentWeed, I've been trying to use the array notation, but sometimes it doesn't seem to work as it should. I don't have an example of this problem now, but when it happens again, I'll be hitting you up.

    IMS

  6. #6
    Member
    Join Date
    Nov 2006
    Posts
    69
    Thanks Y'all, got it now....

    believe it or not, I have used Flash for years and never come across the eval() function. Kinda funny realy.

    set(eval("a"+i+"._x"),eval("b"+i+"._x"));

    worked in the example that I gave in the title.

    Thanks again.

  7. #7
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    Quote Originally Posted by IMS
    silentWeed, I've been trying to use the array notation, but sometimes it doesn't seem to work as it should. I don't have an example of this problem now, but when it happens again, I'll be hitting you up.

    IMS

    Sure let me know when you encounter a problem using array notation
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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