1 Reply Latest reply on Apr 28, 2010 5:49 AM by Ned Murphy

    Adding text via a Button?


      So I create the text with the following code, but when I include the text within a button (AddT1.onRelease), it doesn't work.  Any suggestions?


      Thanks in advance




      var my_str1:String = "Text (1)";


      // Create a TextFormat object,
      // and apply its properties.
      var my_fmt1:TextFormat = new TextFormat();
      with (my_fmt1) {
          font = "Arial";
        //  bold = true;
          align = "center";
          size = 12;


      // Obtain metrics information for the text string
      // with the specified formatting.
      var metrics:Object = my_fmt1.getTextExtent(my_str1);


      // Create a text field just large enough to display the text.


      AddT1.onRelease = function() {
      this.createTextField("Text1", this.getNextHighestDepth(), 220.8, -189, 185, 20);
      Text1.type = "input";
      Text1.wordWrap = true;
      Text1.multiline = true;
      Text1.antiAliasType = "advanced";


      // Assign the same text string and TextFormat object to the Text1 object.
      Text1.text = my_str1;



        • 1. Re: Adding text via a Button?
          Ned Murphy Adobe Community Professional & MVP

          I can't say I have the answer as to why it doesn't work, but it seems to center around "this"  Within that function, "this" refers to the AddT1 object.  And for some reason the code won't work in doing that.  But if I remove the "this" from "this.createTextField", then the textfield appears.  Also, if I change it to "_root.createTextField" it works.  Since you have a _y value of -189 you probably won't see it when you test.