6 Replies Latest reply on May 11, 2007 7:48 AM by Newsgroup_User

    what's wrong with this code?

    chopTheWood Level 1
      No matter what I do, the text size is always the same (about 10 pt) when I load it into "main_txt" from a .txt file. I have to have an input field and non-html.

      //create a text field and specify parameters

      _root.createTextField("main_txt", 10, 0, 0, 417, 464);
      main_txt.type = "input";
      main_txt.border = false;
      main_txt.background = false;
      main_txt.multiline = true;
      main_txt.html = false;
      main_txt.selectable = true;
      main_txt.wordWrap = true;
      main_txt.variable = "sortedDir";
      main_txt.scroll = true;var txt_fmt:TextFormat = new TextFormat();

      // Specify paragraph and character formatting.
      txt_fmt.size = 24;
      main_txt.setTextFormat(txt_fmt);
        • 1. Re: what's wrong with this code?
          Level 7
          chopTheWood,

          > No matter what I do, the text size is always the same (about 10
          > pt) when I load it into "main_txt" from a .txt file. I have to have
          > an input field and non-html.

          The TextField.setTextFormat() method must be applied after the text has
          loaded (otherwise, use TextField.setNewTextFormat()).

          > main_txt.variable = "sortedDir";

          The var (or here, variable) property is an old, old throwback to the way
          text fields were populated back in Flash 4 (gosh, maybe even Flash 3). It
          still works, sure, but I recommend you use the TextField.text property
          instead. Load your external text, and when you know it's loaded -- say, via
          the LoadVars.onLoad event -- set your main_txt.text property to the desired
          string.


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: what's wrong with this code?
            isaacewing
            is this for as2 or as3
            • 3. Re: what's wrong with this code?
              chopTheWood Level 1
              this is for as2
              • 4. Re: what's wrong with this code?
                chopTheWood Level 1
                Thanks.. I'll try your suggestion .. if I understand it correctly. By the way, in actual practice I put the formatting code:

                txt_fmt.size = 24;
                main_txt.setTextFormat(txt_fmt);

                about 10 or 15 frames after the code to load the text field, to give it a chance to finish loading but it didn't work. It seems that there are so many different ways to do things in Flash, it gets complicated. I'm an old "Hypercard" programming dinosaur and HC seemed easier to me, but that might be do to the fact I was younger then and learning came easier. The freedom of doing just about anything with Flash has its costs (choosing between many options) like anything else. As one philosopher put it, one is "condemed to be free" .
                ...thanks
                • 5. Re: what's wrong with this code?
                  Level 7
                  chopTheWood,

                  > Thanks.. I'll try your suggestion .. if I understand it correctly.
                  > By the way, in actual practice I put the formatting code: [...]
                  > about 10 or 15 frames after the code to load the text field, to
                  > give it a chance to finish loading but it didn't work.

                  Hrrm. Well, if you use LoadVars and format the text field in response
                  to the onLoad event, you should (in theory) be guaranteed success. I would
                  also run some isolated tests on dynamic versus input text fields, to see how
                  formatting affects each. Something in my own fuzzy memory is suggesting
                  that input text fields have issues with input formatting, though maybe that
                  was for HTML only. In any case, make sure you're using the
                  setNewTextFormat() method instead of setTextFormat(). :)


                  David Stiller
                  Adobe Community Expert
                  Dev blog, http://www.quip.net/blog/
                  "Luck is the residue of good design."


                  • 6. Re: what's wrong with this code?
                    JackGordon
                    To clarify what Dave was saying.. You won't have to put the code on a later frame, you can do it all in one frame using LoadVars to load your text file. Here's an example:

                    my text file (named Test.txt) looks like this: text=hey world