This content has been marked as final. Show 4 replies
I found a way to do this, but it's a bit clunky. If anyone knows a better way would be pleased to hear it.
This seems to work:
Put the first two children into a VBox with a creationComplete event.
In the event handler, set the TitleWindow width and height equal to the VBox width and height, adding to them the widths of the TitleWindow borders.
Then set TitleWindow.autoLayout = true; and then call validateDisplayList().
Hi Doug - What exactly are you trying to do? Is the third child being added dynamically, and you want it added above the first child? If so, you can use the addChildAt() method when adding the child to the container. addChildAt() takes an index and the child object is added at that index and all other children are reshuffled to maintain the ordering. IE:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical">
<mx:TitleWindow layout="vertical" id="tw">
<mx:Button id="a" />
<mx:Button id="b" click="go();"/>
private function go():void
var c:Button = new Button();
Does that help, or am I misinterpreting what you're trying to do?
The problem is that the third child has to sit on top of the first child, but in a Panel-type container, the only way I can find to get it to do this is to set TitleWindow.layout = "absolute", otherwise, depending on how you do it, the third child either sits immediately after the second child or (astonishingly) behind the TitleWindow (to discover this I had to change its y position to zero and I could then see it through the semi-transparent TitleWindow border) even though it is definitely the third child.
Once you set absolute layout, the TitleWindow size becomes the same as the first child only.
As far as I can see, you have two options with layout in a Panel-type container, either auto (which can be either vertical or horizontal), or absolute. My problem is that I need auto for two of the children and absolute for the other.
In my solution that does seem to work reliably, I first use it in absolute mode to get the third child positioned correctly, and then in auto mode to get it to size correctly.
I should add that I can't add the third child until after the first child's creationComplete event fires as I need to know the co-ordinates of the first child in order to place the third child correctly.