A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Adding numbers to variable names!?!?!

  1. #1
    I Am
    Join Date
    Nov 2000
    Posts
    68

    Adding numbers to variable names!?!?!

    Hi,


    I have 13 variables that I want set equal to 13 other variables. This second set of variables are paths to files.

    code:

    _root.img0 = imgThumb0





    where imgThumb0 = db_pics/IndianRiver.jpg

    Ok, simple so far.

    Now, I don't want to type out _root.img0 = imgThumb0, _root.img1 = imgThumb1, _root.img2 = imgThumb2, etc...


    So, I created an array that increments everytime the loop is run through, like this:

    code:

    for (a=0; a<13; a++) {
    _root.img[a] = imgThumb[a];
    }





    STOP... it doesn't work, so I try this:

    code:


    for (a=0; a<13; a++) {
    _root.img[a] = ["imgThumb" + a];
    }



    and this:

    code:


    for (a=0; a<13; a++) {
    _root.img[a] = [imgThumb + a];
    }




    Still doesn't work...


    It's not successfully putting the number on the end of the string and then using that entire string (imgThumb3, for instance) as the variable to grab the path.


    What I need, in the end, is for _root.img[a] to be equal to the path of the picture for whatever (imgThumb + a) is....


    I'm not sure I've totally made myself clear, but if you could help me out I'd really appreciate it..


    Thanks...
    -Miz

  2. #2
    Senior Member
    Join Date
    Oct 2000
    Location
    Brazil
    Posts
    291
    try this

    for (a=0; a<13; a++) {
    _root["img"+a] = _root["imgThumb"+a];
    }

  3. #3
    Junior Member
    Join Date
    Sep 2003
    Posts
    18

    THANK YOU!

    THANK YOU, THANK YOU, THANK YOU.

    I have been going through tutorials, forum threads, and 'tfm' to figure out how to do this for 2 days.

    I even found a tutorial called variable variables and still couldn't get it to work.

    All I had to do was take a '.' out...

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