9 Replies Latest reply on Nov 20, 2009 2:10 PM by Flex harUI

    How do I tame the TextArea?

    Jerry62712 Level 1

      What I would like is for the TextArea to:

       

      1. if there is one line of stuff in it, only be as tall as one line

      2. if there are two lines of stuff in it, be as tall as two lines (no scroll bar)

       

      Any ideas?

        • 2. Re: How do I tame the TextArea?
          Gregory Lafrance Level 6

          That is my coobook post. Just be aware that it works good as a standalone control, but if used as an itemRenderer, especially in a DataGrid, it does not work well.

          • 3. Re: How do I tame the TextArea?
            Jerry62712 Level 1

            Hi, Greg.

             

            Just to make sure I understand it, you are extending the TextArea with DynamicTextArea.  If I were to have this and assigned it a string of "123" it would automatically resize itself to be as tall as one sentence.  If I were to assign it a string of "pretend this is very long" it would automatically resize itself to be as tall as two, three or whatever sentences?

             

            I see you turned off scroll policy so it wouldn't be one sentence tall with a scroll bar for the rest, right?

             

            Finally, if I change the size of the text (currently between 12px and 20px) the container will automatically resize as well?

             

            I don't use this in any exotic way, my skill level is way too low for that.  I just plop the control on the screen and either alter the content (English or Spanish) or alter the font size.  I don't have it in a datagrid (should I be doing that?).  I do have it wrapped in multiple HBox containers - a lot of them.  One to hold the line across the form so the two sides with two columns doesn't get out of order, one to hold the TextArea, one to hold the container of the TextArea, one to hold the TextInput, one to hold that container, one to hold both of them.

             

            This was the solution tech support gave me for the problem of the label getting longer forcing the data off the screen.  It works even if it seems goofy to me.

            • 4. Re: How do I tame the TextArea?
              Gregory Lafrance Level 6

              This link on my web site shows the control in action.

               

              http://www.chikaradev.com/learning/flex3/itemrenderers/DynamicTextArea/DynamicHtmlTextArea .html

               

              It might not resize smaller, and it might have other problems, as I created it to get someone else in these forums started toward a solution.

               

              So it might still need some work.

               

              If this post helps, please mark it as such.

              • 5. Re: How do I tame the TextArea?
                Jerry62712 Level 1

                I'm probably doing it wrong.  Here is my mxml code:

                <DHSclasses:DynamicTextArea id="resultEarnedIncomeLimitLabel"
                  text=" " toolTip=" "
                  wordWrap="true"
                  styleName="labelStyle"
                  editable="false"
                  focusThickness="1"
                  width="100%"
                  tabIndex="27" />

                 

                I have an import for it (obviously in folder DHSclasses) and the tag appeared in code assist so at least the IDE was able to make the connection.  But I got this error and the results would not display:

                TypeError: Error #1009: Cannot access a property or method of a null object reference.
                    at DHSclasses::DynamicTextArea/set text()[C:\Flex Builder 3\FSCalc\FSCalc\src\DHSclasses\DynamicTextArea.as:25]
                    at FSCalc/_FSCalc_DynamicTextArea1_i()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:357]
                    at FSCalc/_FSCalc_HBox12_i()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:356]
                    at FSCalc/_FSCalc_HBox11_i()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:354]
                    at FSCalc/_FSCalc_HBox10_i()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:352]
                    at FSCalc/_FSCalc_HBox9_i()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:350]
                    at FSCalc/_FSCalc_VBox5_i()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:348]
                    at FSCalc/_FSCalc_VBox1_i()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:346]
                    at mx.core::DeferredInstanceFromFunction/getInstance()[E:\dev\3.1.0\frameworks\projects\fram ework\src\mx\core\DeferredInstanceFromFunction.as:81]
                    at mx.states::AddChild/createInstance()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\st ates\AddChild.as:335]
                    at mx.states::AddChild/initialize()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\states \AddChild.as:347]
                    at mx.states::State/http://www.adobe.com/2006/flex/mx/internal::initialize()[E:\dev\3.1.0\frameworks\projects\ framework\src\mx\states\State.as:199]
                    at mx.core::UIComponent/initializeState()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\ core\UIComponent.as:7321]
                    at mx.core::UIComponent/commitCurrentState()[E:\dev\3.1.0\frameworks\projects\framework\src\ mx\core\UIComponent.as:7099]
                    at mx.core::UIComponent/setCurrentState()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\ core\UIComponent.as:7053]
                    at mx.core::UIComponent/set currentState()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\core\UIComponent.as:4339 ]
                    at FSCalc/swapToResultsState()[C:\Flex Builder 3\FSCalc\FSCalc\src\scripts\FSUtil.as:74]
                    at FSCalc/__calculateButton_click()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:1488]

                I'm not sure why it is a null.  Did I need to include some other property to set?

                 

                [edit: I changed the default text and tooltip properties to some value and it still didn't work]

                 

                Thanks,

                Jerry

                • 6. Re: How do I tame the TextArea?
                  Gregory Lafrance Level 6

                  For some reason if you initially set text such as this text = " " it fails.

                   

                   

                  • 7. Re: How do I tame the TextArea?
                    Jerry62712 Level 1

                    I stepped through the debugger after I changed it so the "text" and "tooltip" had a value ("residence").  In my code I put in the values I wanted and at this line:

                                textField.text = val;
                    I found val="Resident".  textField in the debugger showed as null.   I know I'm doing something wrong.  Here is the parts:

                      <mx:Script>
                        <![CDATA[
                            import DHSclasses.AutoScroll12;
                            import DHSclasses.DynamicTextArea;

                    (mxml line 34)

                                <mx:VBox id="firstLineResultsVBox"
                                    width="100%">
                                    <mx:HBox id="firstLineResultsHBox"
                                        width="100%">
                                        <mx:HBox id="firstLineResultLeftDummy1"
                                            width="50%">
                                            <mx:HBox id="firstLineResultLeftDummy2"
                                                width="86%">
                                                <mx:HBox id="firstLineResultLeftLabel"
                                                    width="100%">
                                                    <DHSclasses:DynamicTextArea id="resultResidenceSizeLabel"
                                                        text="residence" toolTip="residence"
                                                        wordWrap="true"
                                                        styleName="labelStyle"
                                                        editable="false"
                                                        focusThickness="1"
                                                        width="100%"
                                                        tabIndex="25"/>
                                                </mx:HBox>
                                            </mx:HBox>

                    (mxml Line 346)

                            override public function set text(val:String):void{
                                textField.text = val;
                                validateNow();
                                height = textField.textHeight;
                                validateNow();
                                }

                    (DynamicTextArea line 24 - I added some white space between functions)

                    TypeError: Error #1009: Cannot access a property or method of a null object reference.
                        at DHSclasses::DynamicTextArea/set text()[C:\Flex Builder 3\FSCalc\FSCalc\src\DHSclasses\DynamicTextArea.as:25]
                        at FSCalc/_FSCalc_DynamicTextArea1_i()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:357]
                        at FSCalc/_FSCalc_HBox12_i()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:356]
                        at FSCalc/_FSCalc_HBox11_i()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:354]
                        at FSCalc/_FSCalc_HBox10_i()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:352]
                        at FSCalc/_FSCalc_HBox9_i()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:350]
                        at FSCalc/_FSCalc_VBox5_i()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:348]
                        at FSCalc/_FSCalc_VBox1_i()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:346]
                        at mx.core::DeferredInstanceFromFunction/getInstance()[E:\dev\3.1.0\frameworks\projects\fram ework\src\mx\core\DeferredInstanceFromFunction.as:81]
                        at mx.states::AddChild/createInstance()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\st ates\AddChild.as:335]
                        at mx.states::AddChild/initialize()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\states \AddChild.as:347]
                        at mx.states::State/http://www.adobe.com/2006/flex/mx/internal::initialize()[E:\dev\3.1.0\frameworks\projects\ framework\src\mx\states\State.as:199]
                        at mx.core::UIComponent/initializeState()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\ core\UIComponent.as:7321]
                        at mx.core::UIComponent/commitCurrentState()[E:\dev\3.1.0\frameworks\projects\framework\src\ mx\core\UIComponent.as:7099]
                        at mx.core::UIComponent/setCurrentState()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\ core\UIComponent.as:7053]
                        at mx.core::UIComponent/set currentState()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\core\UIComponent.as:4339 ]
                        at FSCalc/swapToResultsState()[C:\Flex Builder 3\FSCalc\FSCalc\src\scripts\FSUtil.as:74]
                        at FSCalc/__calculateButton_click()[C:\Flex Builder 3\FSCalc\FSCalc\src\FSCalc.mxml:1488]

                    See the attached screen print showing "this" and the "val" values.

                    • 8. Re: How do I tame the TextArea?
                      Jerry62712 Level 1

                      I thought it might be that the super (TextArea) wasn't being included so I explicitly did an import on it in the script area of the mxml duplicating the explicit import you were doing, but it didn't make any difference.  Sigh.

                       

                      As the only null item I see (see the attachment) is the superclass and as I would expect it to be null until something is put into it, I'm assuming the TextArea class is not being found.  Sound reasonable?

                      • 9. Re: How do I tame the TextArea?
                        Flex harUI Adobe Employee

                        There is a "component lifecycle".  Children are not created right away.  If you use the lifecycle methods appropriately, the children will be available.  See the doc on custom components and the methods commitProperties, measure and updateDisplayList.

                         

                        Alex Harui

                        Flex SDK Developer

                        Adobe Systems Inc.

                        Blog: http://blogs.adobe.com/aharui