1 Reply Latest reply on Aug 22, 2006 3:39 AM by Newsgroup_User

    save textformat object instead of reference

    Level 7
      I am working with dynamic text fields. I noticed when I write an empty
      string into the text property it loses its textformat.


      So I tried to save the textformat before writing values into that field
      and then set it again after that. But it does not work with the
      gettextformat funciton.

      my code:

      this.createTextField("my_txt", 1, 100, 100, 300, 100);
      my_txt.embedFonts = true;
      my_txt.autoSize = "left";
      my_txt.multiline = true;
      my_txt.wordWrap = true;
      var my_fmt:TextFormat = new TextFormat();
      my_fmt.color = 0xFF0000;
      my_fmt.underline = true;
      my_fmt.font = "Arial"
      my_txt.text = "This is my first test field object text.";


      var tf:TextFormat = new TextFormat();
      tf = my_txt.getTextFormat();
      my_txt.text = "";
      my_txt.text = "This is my first test field object text.";
      my_txt.setTextFormat(tf);


      But it does work when I set the my_fmt on it. It seems that the variable
      tf only gets the reference instead of the whole objectduplicate. How can
      I fix that?

      Thanks for any help!
        • 1. Re: save textformat object instead of reference
          Level 7
          > this.createTextField("my_txt", 1, 100, 100, 300, 100);
          > my_txt.embedFonts = true;
          > my_txt.autoSize = "left";
          > my_txt.multiline = true;
          > my_txt.wordWrap = true;
          > var my_fmt:TextFormat = new TextFormat();
          > my_fmt.color = 0xFF0000;
          > my_fmt.underline = true;
          > my_fmt.font = "Arial"
          > my_txt.text = "This is my first test field object text.";

          I think I forgot to set it here.

          my_txt.setTextFormat(my_fmt)

          Seems to work now.


          > var tf:TextFormat = new TextFormat();
          > tf = my_txt.getTextFormat();
          > my_txt.text = "";
          > my_txt.text = "This is my first test field object text.";
          > my_txt.setTextFormat(tf);