A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Variable Help

  1. #1
    Junior Member
    Join Date
    May 2013

    Variable Help

    Hey Guys, I am kinda new to action script so bear with me if this is a bit of a noob question.

    I have a series of text fields within buttons (movie clips). To change the text of these fields you would call C1_btn.C1_Name.text = "some string" (changing 1 to 2, 3, 4, etc. for all the fields totaling 10)

    var myString:String;
    var i:int;
    for(i=1; i<10; i++) {
    myString = "C" + i + "_btn.C" + i + "_Name.text"; //This will look like this "C1_btn.C1_Name.text".
    myString = "Chapter" + i; // Change the text of the field in the button...

    // C1_btn.C1_Name.text = "chapter 1"; // tested and works.

    How would i do this so that the second call to myString would be taken literally as C1_btn.C1_Name.text because that is what I actually want to change.

    Hope this makes sense and someone has a clean solution. Thanks in advance.


  2. #2
    Junior Member
    Join Date
    May 2013

    Red face Maybe my question was stated unclearly....

    Still hoping someone can help me out...

    Maybe this will help explain my problem better and what I am hoping to achieve....

    for (var i:int=1; i<11; i++){
    C1_btn.C1_Name.text = playlist[i];
    C1_btn.C1_Desc.text = desclist[i];

    In the example above, how do I get the number 1 (both spots) to increment with i... I am certain there must be a way to do this but for the life of me i just cant figure it out.

    Effectively what Id like is something that would work like this...

    Ci_btn.Ci_Name.text = playlist[i]

    Where i gets updated with each for loop.

    Please someone help me....

  3. #3
    Junior Member
    Join Date
    May 2013
    ok, making a little progress here....

    this["C" + i + "_btn.C" + i + "_Name.text"] = playlist[i];

    seems to no longer error out but it does not populate the text field as expected.

  4. #4
    Senior Member
    Join Date
    Jan 2011
    PHP Code:
    var path:String;
    for (
    i=0i<5i++) {
    path "c" + (i+1) + "_btn";
    this[path].c_name.text "Chapter" + (i+1);


  5. #5
    Junior Member
    Join Date
    May 2013


    Nice, i like it. Ill try it when i get home tonight. Thanks for the reply. This little issue has plagued me for a bit. If this works, ill be able to wipe out about 30 if then else statements.

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