11 Replies Latest reply on May 15, 2008 12:45 AM by Heffalompen

    Load HTML into TextField or Text Components!

    Heffalompen
      Hi all!

      I'm trying to load 4 HTML documents into 4 different TextArea components (infoTxt1, infoTxt2, infoTx....). In the attached code I use/load the same HTML document to populate the components just to simplify the testing.
      This loop will not work. Can anyone tell me why or if there is a better way to load several HTML into components dynamically? It works IF it only loop once.

      Thanks
        • 1. Load HTML into TextField or Text Components!
          Heffalompen Level 1
          Can anyone help me with this? I really appreciate some guideance
          • 2. Re: Load HTML into TextField or Text Components!
            kglad Adobe Community Professional & MVP
            there's no problem with your code (if your textfield instance names are correct and your html path/filename is correct).
            • 3. Re: Load HTML into TextField or Text Components!
              Heffalompen Level 1
              Thanks Kglad for taking the time. Like so many times before I am more likely to find a solution when you me give advice.

              I have checked for spell errors but I'm quite sure there aren't any. I believe the code is bad somewhere. Probably caused by the if statement? Here is the updated code with comments.

              PS I have now extracted the code into a new flash file and change the path to " _root["infoTxt" + n].text". Don't know how to avoid " _root" in the path. But it works loading content outside the "for" loop.

              Hope this make sense for anyone?
              • 4. Re: Load HTML into TextField or Text Components!
                kglad Adobe Community Professional & MVP
                your for-loop completes execution (and n=5) before any code inside your onData() methods will execute. so, by the time any file loads n=5 and that's what you'll see in your onData() method and you won't assign any code to your first 4 textfields.

                • 5. Load HTML into TextField or Text Components!
                  Heffalompen Level 1
                  OK, I had my suspicion it was something like that causing my problems.
                  Kglad: Thanks, I understand what you are saying but my follow up question is how on earth can I approach a correction in the code to make the for-loop "wait" or something for the onData. This is way beyond my knowledge, sorry!

                  The easiest way would be to load them one-by-one outside a loop, but for my own satisfaction I'm desperate to learn more and to find this out.

                  Anyone?

                  • 6. Re: Load HTML into TextField or Text Components!
                    kglad Adobe Community Professional & MVP
                    i don't see any easy way to use a for-loop. i'd use:

                    • 7. Load HTML into TextField or Text Components!
                      Heffalompen Level 1
                      Thanks Kglad!
                      I didn't think of that approach and putting everything into a function. But, I still get only the last one displayed when setting up all four to load at the same time:

                      loadDataF(1);
                      loadDataF(2);
                      loadDataF(3);
                      loadDataF(4); // only this will display in the text component

                      Trying only loadDataF(1) only loads the right text in infoTxt1 so you're one step closer than I ever was. I got it to load 1 but in wrong container:(

                      As you probably understand, and as you have shown, the whole clue is to make compact code. Maybe this is just where I have to say: It's not possible?
                      The whole day has gone now an it's now past 9 pm here. I better get home now. I have a bad concious, not only for dragging you into this, but also for being absent to the wife and kids. Damn!

                      Can't winn'em all, but thanks again for helping us mortals!
                      • 8. Re: Load HTML into TextField or Text Components!
                        kglad Adobe Community Professional & MVP
                        using the code i gave change:

                        _root["infoTxt"+dataNum].text = theText;

                        // to

                        _root["infoTxt"+dataNum].text = theText;
                        trace(_root["infoTxt"+dataNum]);

                        // and paste the output panel result
                        • 9. Re: Load HTML into TextField or Text Components!
                          Heffalompen Level 1
                          OK, I've done that and the result is a never ending output of:
                          _level0.infoTxt1
                          _level0.infoTxt1
                          _level0.inf... an so on.

                          Only infoTxt1 is populated with the right text using only "loadDataF(1)".

                          I've included the sourcefiles here.

                          Maybe those could help better understand?

                          Thanks again :)
                          • 10. Re: Load HTML into TextField or Text Components!
                            kglad Adobe Community Professional & MVP
                            change:

                            loadDataF(dataNum++);

                            to:

                            dataNum++;
                            loadDataF(dataNum);
                            • 11. Load HTML into TextField or Text Components!
                              Heffalompen Level 1
                              YEAH!

                              TRULY AMAZING, KGLAD :)

                              Sorry for shouting out, but I just love to get this kind of help. I would never have figured this one out by my self and the good thing is I actually understand what's going on in your code and can use that in other cases.
                              You came through as you you always do, and a million thanks for taking the time.

                              Have a wonderful day :)

                              Answer:
                              To load several "html" documents into several textarea components on stage you can use kglads code:

                              var dataNum:Number;
                              loadDataF(1);
                              function loadDataF(n:Number) {
                              dataNum = n;
                              this["tabData"+n] = new LoadVars();
                              this["tabData"+n].onData = function(theText:String):Void {
                              if (theText != undefined) {
                              _root["infoTxt"+dataNum].text = theText;
                              trace(_root["infoTxt"+dataNum]);
                              if(dataNum<4){
                              dataNum++
                              loadDataF(dataNum);
                              }
                              }
                              };
                              this["tabData"+n].load("artist"+n+".html");
                              }