4 Replies Latest reply on Dec 6, 2013 8:58 AM by cassadee

    mx:Text autoSize?

    cassadee
      Hi!

      I have a mx:Text component with a specified width. On every change of the text property in this Text component the height should be updated to fit the whole text. How is that possible?
      Anyone knows a work-around with other classes?


      When I try following...
      ---------------------------
      myText.text = "targettext, can grow multiline";
      myText.height = myText.textHeight;
      ---------------------------
      ... the height property changes, however always too late (on the next programmturn).

      change="updateMyText()" in the .mxml also haven't worked.

      Eventlistener on FlexEvent.DATA_CHANGE won't get called.

      validateNow() haven't worked.


      I'm very tired of this problem and hope, someone can help me.

      mfg Tschouba
        • 1. Re: mx:Text autoSize?
          injpix Level 3
          The height of mx.controls.Text should be adjusted automatically when text is assigned. If you assigned a function to the dataChange property, then that will fire off an event (FlexEvent.DATA_CHANGE) to that assigned function when the *data* property of Text gets assigned a value. The data property takes an Object type for its value.
          • 2. Re: mx:Text autoSize?
            cassadee Level 1
            Thanks for your reply!

            The height of the mx.controls.Text gets only adjusted automatically, when I set the text property in the .mxml file on initialize (<mx:Text text="myText" />).
            But I want to change the text dynamically while the program flow with myText.text="myNewText". Then the height should be adjusted to fit the whole new text.

            Can I use the data property to display the text?
            • 3. Re: mx:Text autoSize?
              injpix Level 3
              The data property is designed to be used when a Text instance is implemented as an item render or for data binding. So as always when troubleshooting, limit the amount of variables to the equation.

              Below is a minimalist example of a Text instance that will get its height adjusted when a Button is clicked.

              Does this help?
              • 4. Re: mx:Text autoSize?
                cassadee Level 1

                You're right, the height gets adjusted automatically in your example.
                However, in my target programm it wasn't so, althougt it was the same text-component-code as in yours.

                So again I tried around and finally I found my error: At the canvas tag (that was surrounding the Text component) autoLayout was set to false. Because of that the height of the text inside wasn't adjusted automatically.
                autoLayout="true" --> all works fine

                Thanks for your help, myIP!

                Greets