8 Replies Latest reply on Mar 31, 2007 9:05 AM by kglad

    iterate through all dynamic text variables

    jigidyjim Level 1
      Hello,

      I'd like to be able to iterate through all of the dynamic text variables in my flash movie, and I'd like it so that if I add new text to this movie, it will show up in the iteration.

      Essentially, I want to do something like this:

      for (i in _root) {
      trace(i);
      }

      While this seems to print out all the variables in root, it prints more than just the dynamic text variables, and also doesn't iterate down through various objects to find the dynamic text variable.

      Is there any way I can accomplish this in action script?

      Thanks!
        • 1. Re: iterate through all dynamic text variables
          kglad Adobe Community Professional & MVP
          you can iterate through everything but you can't limit the iteration to just dynamic text variables. what is it you're trying to do?
          • 2. Re: iterate through all dynamic text variables
            jigidyjim Level 1
            It's kind of complicated. Essentially I'm going to have a bunch of dynamic text fields, each of which will point to a different variable.

            I want to do things like go through all those variables and set them to some value, without knowing before hand what those variable names are or how many there are.

            It would be nice if I could start from the root, iterate through everything in my movie. If the object is a text object, then maybe I could look at what variable it is assigned to, and that would solve my problem...

            I tried using typeof(), but when I do the for (i in _root) everything has a typeof string, so that doesn't help much....
            • 3. Re: iterate through all dynamic text variables
              jigidyjim Level 1
              This person has described the situation I'm encountering (though it looks like they didn't get a response):

              http://www.webforumz.com/lo-fi/t-25096.html

              • 4. Re: iterate through all dynamic text variables
                kglad Adobe Community Professional & MVP
                that's correct. you cannot isolate text variables and you cannot isolate textfields with typeof().

                but you could probably find an acceptable solution by using typeof() to check for objects and then check the html property of all objects and then check the text or htmlText property, as is appropriate, to effectively isolate all textfields. does that sound acceptable?

                the link you posted also has a straight-forward solution because checking for a movieclip only returns movieclips (and references to movieclips.
                • 5. Re: iterate through all dynamic text variables
                  jigidyjim Level 1
                  Thanks, that sounds great...

                  The only problem is I'm still not sure how to iterate through movie clips or objects... when I iterate using for (i in _root) it's just all strings that get returned...

                  Thanks again for your help.
                  • 6. Re: iterate through all dynamic text variables
                    kglad Adobe Community Professional & MVP
                    to iterate through all textfields on a given _level that have text assigned:

                    • 7. Re: iterate through all dynamic text variables
                      jigidyjim Level 1
                      Great! That code helps me a lot.

                      There are still two weird issues.
                      1) the test for tl[obj].text seems to always turn out to be false. However, if I trace the value of text, I'll see the text.

                      Example:
                      trace(tl[obj].text); // This will display the value in the text field
                      if (tl[obj].text) // This is always returning false.

                      Any ideas?


                      The 2nd issue might be more difficult - some of my text objects don't appear until later in the movie (i.e. frame 10). It sort of looks like this looping doesn't see objects that appear in the future. Do I need to advance the frame 1 by 1 and repeat this looping process until the text appears? Maybe instead I can always have the text in the first frame, but have it be invisible or something?
                      • 8. Re: iterate through all dynamic text variables
                        kglad Adobe Community Professional & MVP
                        i can't recreate that problem with a textfield's text. if the text property is undefined or the textfield has no text, the boolean is false. otherwise, it's true.

                        post a link to a fla that contains a textfield with text and the boolean is false.

                        there is no work-around for the 2nd issue. if the objects don't exist when the code is executed, the code cannot detect the objects.