creationComplete恐怕是flex用的最多的事件了,不管啥,application标签后面接个creationcomplete事件处理函数,做为程序的起点。这种做法是没错的,可是有些时候它也不是都管用。先看看来自devguide_flex3的论述:
The preinitialize event occurs too early in the component life cycle for most initialization activities. It is useful, however, in the rare situations where you must set the properties on a parent before the children are created.
To configure a component before Flex has determined its visual appearance, use the initialize event. For example, use this for setting properties that affect its appearance, height, or width.
Use the creationComplete event for actions that rely on accurate values for the component’s size or position when the component is created. If you use this event to perform an action that changes the visual appearance of the component, Flex must recalculate its layout, which adds unnecessary processing overhead to your application.
Use the updateComplete event for actions that must be performed each time a component’s characteristics change, not just when the component is created.
这是flex components initialization lifecycle里论述的关于组件初始化的过程(个人认为这是flex的超级重点)。其它事件不看了。creationcomplete事件发生在某个组件(以及它的子组件)完全建立的时候,包括样式,大小,布局完成。也就是讲,是你能看到UI的时候。它隐含了一些意思在里面(个人经验之谈),很可能在实际操作过程中被忽略掉。
必须可见 。我在这点上吃了几次亏。creationcomplete的时机是布局已经完成的时刻,那如果某些子组件不在布局之内呢,比如tag navigator, viewstack(其它的我没试过,不好讲)。它的还没被选中的子组件就没有初始化,访问它就报错了。
只发生一次 。就是建立的时候,如果以后布局有变化,发出的是updatecomplete 事件。
每个组件都有 。除了application,还有它的子组件,子组件的子组件… 。地球人都有呀。这一点可以做为第一点的解决方案,就是在子组件里各自建立creationcomplete的处理函数,这样对数据模块化也有好处。
文章来自: 闪无忧(www.5uflash.com) 详文参考:http://www.5uflash.com/Flex-AIR/Flexziliao/4424.html