3 Replies Latest reply on Nov 26, 2009 9:43 AM by Flex harUI

    ItemRender creates 2 of each object. Variable height TextArea problems

    Stuart McD

      Ok. I'll start with what I was trying to acheive to explain how I ended up here. I wanted TextArea with no scroll bars that resized to the height of the text. Googling it seems the way to do this is to extend TextArea and use something like

      var numLines:int = this.mx_internal::getTextField().numLines;
      for (var i:int = 0; i < numLines; i++)
           totalHeight += this.mx_internal::getTextField().getLineMetrics(i).height;
      this.height = totalHeight;
      

      to calculate the height. This works, but I then put the component (WrappedText) in a DataGrid and used an itemRenderer on it and things got wrong.

       

      What I'm seeing is that with just one row in the DataGrid there are TWO WrappedText objects created. The only difference when I trace them is their parent e.g. If I do this.toString() in the creationComplete

      MADE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer13._Renderer_WrappedText1
      MADE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer27._Renderer_WrappedText1
      

       

      The problem this causes is one of these objects has numLines equal to the number of characters in the text. The other has the correct value (1). So what happens is the dataGrid gets the wrong height.

       

      I've trimmed everything down so there is just one row in the table etc. Here's the trace output. MADE is creationComplete of the WrappedText and RESIZE is when it recalculates it's size (when the text is set), and GRID HEIGHT is displayed by the creationComplete of  the DataGrid

       

      MADE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer13._Renderer_WrappedText1
      RESIZE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer13._Renderer_WrappedText1 HEIGHT= 14 NUM LINES 1
      RESIZE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer13._Renderer_WrappedText1 HEIGHT= 196 NUM LINES 14
      MADE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer61._Renderer_WrappedText1
      RESIZE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer61._Renderer_WrappedText1 HEIGHT= 14 NUM LINES 1
      RESIZE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer61._Renderer_WrappedText1 HEIGHT= 196 NUM LINES 14
      RESIZE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer61._Renderer_WrappedText1 HEIGHT= 14 NUM LINES 1
      GRID HEIGHT= 1402
      
      

       

      So my main question is is this a reasonable approach or is there another way do what I want? ie. a DataGrid containing blocks of variable height, word wrapped text?

       

      Also, can someone explain what's going on here so I understand what I'm doing wrong e.g. why do 2 objects get created?

       

       

      Another interesting(?) data point is that if I put in an ObjectUtil.toString(this.parent) in the creationComplete of WrappedText both objects get the correct numLines value  e.g.

      MADE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer13._Renderer_WrappedText1
      RESIZE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer27._Renderer_WrappedText1 HEIGHT= 14 NUM LINES 1
      RESIZE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer27._Renderer_WrappedText1 HEIGHT= 196 NUM LINES 14
      RESIZE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer27._Renderer_WrappedText1 HEIGHT= 14 NUM LINES 1
      MADE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer27._Renderer_WrappedText1
      GRID HEIGHT= 142
      RESIZE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer13._Renderer_WrappedText1 HEIGHT= 14 NUM LINES 1
      RESIZE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer13._Renderer_WrappedText1 HEIGHT= 14 NUM LINES 1
      RESIZE:  Main4_0.theContainer.theGrid.ListBaseContentHolder8.Renderer27._Renderer_WrappedText1 HEIGHT= 14 NUM LINES 1
      
      

      Note that the NUM LINES has changed and the RESIZE is done after the creationComplete of the grid.

       

      An explanation to the above would be nice as well Why does simply dumping the object cause completely different behaviour?

       

      I've attached the source of my simple text program. Thanks,

       

      Stuart.