R – flex textflow dyniamic height

actionscript-3airflex3

In my flex application I have scenerio like this:
parent to child
Vbox->Canvas->Sprite->Textflow

In this scenerio now I need to have dynamic height of the textflow & its parents. Here the root parent is the itemrenderer of the datagrid I have.

I need the heights of rows to be adjust according the content in it.

Right now I am importing the xml to textflow, then getting the number of lines, text height. Then removing the textflow & adding it again with the measured height according to the number of lines & text height.

How can I achieve it without removing & adding it again, coz it is taking much time in updating?

Thanks in advance.

Best Answer

Right might be a little late to answer this but someone else may benefit. On the canvas or display object housing the TextFlow and sprite add a creationComplete functon.

I don't know if this step is necessary, but it works for me. Add a label with the text thats going to go into TextFlow (with the same font and fontSize), add a creation complete listener to that as well.

Get the height and width from the newly created label e.target.width e.target.height (in the function listening to the creation of label). Set the displayObjects (in the above case Canvas) height and width to these values, then proceed to add the sprite and textflow.

Note: this was a lazy way for me, label uses measureText which would be a more efficent way of doing this.

Related Topic