concatenating a string and a number in flash ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • devowen
    New Member
    • May 2007
    • 1

    concatenating a string and a number in flash ?

    Hi,

    I wonder if anyone can help here ? I know this is a pretty simple thing - but Im just getting into actionscript and Im stuck on one part of something I am trying to do.

    Basically and exmaple of what I am trying to do is - I have three text boxes, txt1,txt2,txt3. I then have another layer with some actionscript on, where I have a loop, and in that loop I have a string with the value 'txt'. I am trying to tag the value of the loop counter on the end of that string, and then use the concatenated result as a reference to populate the relevant txt box.

    I cant seem to get it to work though, it does not recognise the number on the end of the string ?

    Code:
    var str1 = "txt";
    
    var i:Number = 4;
    while (i <5) {
        var str2 = str1 + i;
    	eval(str2).text = "hello";
        i++;
    }
    Any thoughts appreciated.

    Thanks
  • toddford
    New Member
    • May 2007
    • 2

    #2
    Have a look at your code. It would work fine if you had a dynamic text field on the stage named txt4.

    Another way to reference the text field would be to use the array access operator ([]).

    Code:
    this[str2].text = "hello";

    Comment

    Working...