creationComplete event does not show the correct height and width
I have an issue where using MXML, the height and width properties of myBox is correctly acquired but using ActionScript the correct height and width acquired is not correct.
my:Tab extends NavigatorContent (This is NOT the tab in a Tab Bar)
com:myBox extends BorderContainer.<mx:ViewStack id="viewstack_main" width="100%" 开发者_Go百科height="100%" creationPolicy="all">
<my:Tab label="My Tab">
<s:Scroller height="100%" width="100%">
<s:Group height="100%" width="100%">
<com:myBox>
</com:myBox>
</s:Group>
</s:Scroller>
</my:Tab>
</mx:ViewStack>
In the constructor of myBox I set the percentWidth
and percentHeight
to both 100.
In the creationComplete
event of the same myBox, I need to access the height
and width
.
This works all ok with the MXML.
However using ActionScript I need to add another tab.
var navContainer:Tab = new Tab();
viewstack_main.addElement(navContainer);
var scroller:Scroller = new Scroller();
scroller.percentHeight = 100;
scroller.percentWidth = 100;
navContainer.addElement(scroller);
var grp:Group = new Group();
grp.percentHeight = 100;
grp.percentWidth = 100;
scroller.viewport = grp;
var box:myBox = new myBox();
grp.addElement(box);
But unfortunately, in the creationComplete event of box, the height and width properties are NOT what is expected (the height & width after setting 100%). It is 112.
Any ideas as to why this works with MXML but NOT ActionScript?
Referring to initialization sequence in Flex in the moment when your box
is initialized with creationComplete
parent components are still not fully initialized. In your situation it is better to override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
and use real size from there.
The answer was simple. All I had to do was call validateSize(false)
before requesting for the height and width.
精彩评论