1 Reply Latest reply on Aug 17, 2009 9:58 AM by Flex harUI

    overriding measureText

    Zolotoj Level 3

      I am using the following code to prodice text wrap in a linkbutton that is used as an item renderer in a datagrid:

      package modulecode
      {
           import flash.text.TextLineMetrics;     
           import mx.controls.LinkButton;     
           public class linkButtonWordWrap extends LinkButton
           {
                public function linkButtonWordWrap()
                {
                     super();
                }
                override protected function createChildren():void
                {
                     super.createChildren();
                     if (textField)
                     {
                         textField.wordWrap = true;
                         textField.multiline = true;
                     }
                }     
                override public function set data(value:Object):void
                {
                     super.data = value;
                     label = value.link.substr(10);
                }     
                override public function measureText(s:String):TextLineMetrics
                {
                     textField.text = s;
                     var lineMetrics:TextLineMetrics = textField.getLineMetrics(0);
                     lineMetrics.width = textField.textWidth;
                     lineMetrics.height = textField.textHeight;
                     trace(textField.textWidth);
                     return lineMetrics;
                }
      
           }
      }
      

      Column:

      <mx:DataGridColumn headerText="Document" dataField="link" sortable="false"
      textAlign="left" width="400" wordWrap="true" editable="false">
      mx:itemRenderer>
      <fx:Component>
      <modulecode:linkButtonWordWrap color="blue" textAlign="left" fontSize="9" 
      fontWeight="bold" fontStyle="italic" textDecoration="underline">                                                  
      </modulecode:linkButtonWordWrap>
      </fx:Component>
      </mx:itemRenderer>
      </mx:DataGridColumn>
      

      Word wrapping works fine while I am adding new rows. textField.textWidth is about 380.

      But when I delete a row the trace will show textField.textWidth is around 100. AS a result, linkbutton's text is not allocated over the whole column width.

      Any ideas?

       

      Thanks