A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] looping through textboxes

  1. #1
    Member
    Join Date
    Feb 2008
    Location
    Turkey...Istanbul
    Posts
    83

    resolved [RESOLVED] looping through textboxes

    Hi, I have four textboxes on the stage and I need to display the data I get from a external text file...but I seem to have problem in seting a for loop..
    will you please help?
    thanks


    PHP Code:
    on(press){
    loadText = new LoadVars();
    loadText.load("data.txt");
    loadText.onLoad = function() {
     for(
    i=1;i<=4;i++){
     
    name[i].text this.name[i];
     
     }
     
    email.text this.email;
     
    location.text this.location;
    };


  2. #2
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    how is your text file set-up?

    all text fields should show the same data? or a different value from the text file?

    try:

    ["name"+i].text

  3. #3
    Member
    Join Date
    Feb 2008
    Location
    Turkey...Istanbul
    Posts
    83
    Hi Whisper,
    we solved that problem...But whats wrong with this one.. I sometimes get "undefined" values in some textboxes
    could you please fix that ?
    thanks
    PHP Code:
    on(press)
    {
        var 
    bir=new Array(" ","I","you","he","she","it","we","they")
        var 
    sayb=Math.floor(Math.random()*6)+1;
        var 
    sayc=Math.floor(Math.random()*16)+1;
        var 
    iki=new Array()
        for(var 
    i=0;i<=4;i++)
        {
            
    _root["p"+i].text bir[sayb+i];
            }
        
    iki[0]="going to school now";
    iki[1]="drinking milk now";
    iki[2]="eating apples now";
    iki[3]="watching tv now";
    iki[4]="opening the door now";
    iki[5]="reading a book now";
    iki[6]="speaking English now";
    iki[7]="helping students now";
    iki[8]="writing a letter now";
    iki[9]="singing a song now";
    iki[10]="answering the questions now";
    iki[11]="playing tennis now";
    iki[12]="having breakfast now";
    iki[13]="making a cake now";
    iki[14]="drawing a flower now";
    iki[15]="cleaning the board now";
    iki[16]="doing homework now";    
    for(var 
    m=0;m<=15;m++)
        {
            
    _root["t"+m].text iki[sayc+m];
            }


        } 

  4. #4
    亲爱钰 slingsrat's Avatar
    Join Date
    Mar 2002
    Location
    Middle Earth
    Posts
    229
    I see a few errors here. The reason you are getting undefined in _root[p] textboxes is that you are adding "i" to your random number (sayb). Say your random number is 6 your last textbox will have the array element 10 in it of which no such element exists.

  5. #5
    亲爱钰 slingsrat's Avatar
    Join Date
    Mar 2002
    Location
    Middle Earth
    Posts
    229
    Also because you are adding 1 to your random numbers the first elements in your array (element 0) will never be shown.

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