tags:

views:

222

answers:

1

I am working on a flex app that uses XML templates to dynamically create DisplayObjects. These templates define different layouts that can be used for each page of content in the app (ie , 2 columns, 3 columns etc etc). The administrator can select from one of these and populate each area with their content.

The templates add one of 3 types of DisplayObject - HBox, VBox or a third component - LibraryContentContainer (an mxml component that is defined as part of the app) - which is effectively a canvas element with a TextArea inside.

The problem that I am getting is that I need each of these areas to automatically resize to fit the length of the content but don't seem to be able to find an effective way to do so.

In the LibraryContentContainer, when the value of the TextArea is set, I am calling .validateNow() on the LibraryContentContainer. I then set the height property on both the TextArea and LibraryContentContainer to match the textHeight property of the TextArea.

In the following example, this is the LibraryContentContainer, viewer is the TextArea and the value property of the TextArea is bound to this.__Value. v is the variable containing the content for the textarea

this.__Value = v;
this.validateNow();

this.viewer.height = this.viewer.textHeight;
this.height = this.viewer.height; 

This works to a degree in that the TextArea grows or shrinks depending on the length of content, but it's still not great - sometimes there are still vertical scrollbars even tho the size of the TextArea has grown.

Anyone got any ideas?

Thanks

Adam

A: 

I think the problem lies not with your dynamically added components, but with the component they're being added to. How is the height of this component being determined? If you set verticalScrollPolicy and horizontalScrollPolicy on this container to off, do your scrollbars disappear? If that's the case, then you'll need to look at how this component is sized rather than your hbox, vbox, or whatever it is you're adding.

quoo
Hi, thanks for the response.The dynamic components are being added to a Canvas object. It's dimensions are being determined by setting the top, left, right and bottom attributes I need the container to show a scroll bar when necessary - it is the children within that I am looking to sizeso that they never need individual scrollbars.However in case I am missing the point as to why you asked this, I set both scroll policies on the container to off. The outer scroll bars disappear but the dynamic component is now cropped off at the bottom and still has a scrollbar
Addsy
Ah, so I was recommending setting the scroll policys to determine which container the scroll bars were showing up on. I thought perhaps you were sizing the inner containers correctly, but not the outer one, but that seems not to be the case. Is this: this.viewer.height = this.viewer.textHeight;this.height = this.viewer.height; the only sizing code you're applying?
quoo
Well actually its a little trickier than that because I am adding the HBoxes and VBoxes to the Canvas object first then adding the LibraryContentContainers to the HBoxes and VBoxes. These are being sized in 2 different ways. The height of the VBox is determined by adding the heights of all its children. The height of the HBox is determined by finding the largest height of its children
Addsy