4 Replies Latest reply on Sep 29, 2010 7:18 AM by BhaskerChari

    Important:Text control

    Arsohoh Level 1

      Hi all,

       

      I have a mx:Text with width as 200 and this control is within the itemRenderer of HorizontalList and so the Text contents may vary based on the data. So is there any way to find the exact width of the text content in the mx:Text.

       

      When i do Text.width am always getting as 200 which is obvious because thats the width set. But I need the exact width of the overlaid text.

       

      Say for instance, if I have texts like " I'm am Paul " and " This is the test text message for TEXT Control" then i should get the width's of these texts in the TEXT control.

       

      Its urgent pls advice.

        • 1. Re: Important:Text control
          BhaskerChari Level 4

          Hi Arsohoh,

           

          You can try the following code ...

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
              creationComplete="init()">
              <mx:Script>
                  <![CDATA[
                      import mx.controls.Alert;
                      private function init():void{
                          var tf:TextField = new TextField();
                          tf.htmlText = textArea.htmlText;
                          tf.multiline = false;
                          var lineMetrics:TextLineMetrics = tf.getLineMetrics(0);
                 var _textWidth:Number = lineMetrics.width;
                 Alert.show("Actual Text Width = " + _textWidth);
                      }
                  ]]>
              </mx:Script>
             
              <mx:Text id="textArea" width="200" text="You complete a short questionnaire, an oppurtunity to tell us a little more about yourself." />
          </mx:Application>

           

           

           

          Thanks,

          Bhasker

          1 person found this helpful
          • 2. Re: Important:Text control
            Arsohoh Level 1

            Thanks BhaskerChari,

             

            Instead I used textWidth which is a inbuilt property and will be available in the actionscript .

             

            private function init():void{
                                  Alert.show("Actual Text Width = " + textArea.textWidth);
                        }

             

            This worked. Thanks for your suggestion as well.

            • 3. Re: Important:Text control
              Arsohoh Level 1

              I have one more issue here, am using "usehandCursor" property and it should show it only when I mouseOver the text content, but in the current scenario am getting the cursor when I mouse over even on the blank Text.

               

              I just want the usehandCursor to show up only when I mouse over the exact Text content.

               

              Pls Advice.

              • 4. Re: Important:Text control
                BhaskerChari Level 4

                Hi Arsohoh,

                 

                I dont think you will get the Actual Text Width by using textArea.textWidth.....Have you tested it..??

                 

                 

                You can just try simpley putting the below line in the code I gave...

                 

                Alert.show("Actual Text Width = " + textArea.textWidth);

                 

                 

                You will get both Alerts as different...

                 

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
                    creationComplete="init()">
                    <mx:Script>
                        <![CDATA[
                            import mx.controls.Alert;
                            private function init():void{
                                var tf:TextField = new TextField();
                                tf.htmlText = textArea.htmlText;
                                tf.multiline = false;
                                var lineMetrics:TextLineMetrics = tf.getLineMetrics(0);
                       var _textWidth:Number = lineMetrics.width;
                       Alert.show("Actual Text Width = " + _textWidth);
                       Alert.show("Actual Text Width = " + textArea.textWidth);
                            }
                        ]]>
                    </mx:Script>
                   
                    <mx:Text id="textArea" width="200" text="You complete a short questionnaire, an oppurtunity to tell us a little more about yourself." />
                </mx:Application>

                 

                 

                 

                Thanks,

                Bhasker Chari