创建完成事件不显示正确的高度和宽度
我遇到一个问题,使用 MXML 时,可以正确获取 myBox 的高度和宽度属性,但使用 ActionScript 时,获取的正确高度和宽度不正确。
my:Tab 扩展了 NavigatorContent(这不是选项卡栏中的选项卡)
com:myBox 扩展了 BorderContainer。
<mx:ViewStack id="viewstack_main" width="100%" 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>
在 myBox 的构造函数中,我将 percentWidth
和 percentHeight
设置为 100。
在 creationComplete<同一个 myBox 的 /code> 事件,我需要访问
height
和 width
。
这对于 MXML 来说一切正常。
但是使用 ActionScript 我需要添加另一个选项卡。
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);
但不幸的是,在box的creationComplete事件中,高度和宽度属性不是预期的(设置100%后的高度和宽度)。它是 112。
关于为什么它适用于 MXML 而不适用于 ActionScript,您有什么想法吗?
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%" 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
参考Flex中的初始化顺序 当您使用
creationComplete
初始化box
时,父组件仍未完全初始化。在您的情况下,最好覆盖protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
并使用实际大小。Referring to initialization sequence in Flex in the moment when your
box
is initialized withcreationComplete
parent components are still not fully initialized. In your situation it is better to overrideprotected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
and use real size from there.答案很简单。我所要做的就是在请求高度和宽度之前调用
validateSize(false)
。The answer was simple. All I had to do was call
validateSize(false)
before requesting for the height and width.