`

flex creationComplete事件的一些思考

阅读更多

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

分享到:
评论

相关推荐

    看完Flex就可以做出一个小游戏

    Design 视图:按钮,图片 Source 视图 MXML/ActionScript 3.0 ...页面初始化事件creationComplete 表格DataGrid, dataProvider,集合对象Array,ArrayCollection Http请求 HttpService, 报表:饼图,折线图,柱状图

    flex4cookbook

    creationComplete="app_creationCompleteHandler(event)"> <![CDATA[ import mx.events.FlexEvent; protected var names:Array = ['Leif','Zach','Stacey','Seth','Leonard']; protected var titles:Array = ...

    Flex调用xml通过DataGrid遍历简单示例

    creationComplete="service.send()" > <![CDATA[ import mx.controls.Alert; import mx.rpc.events.FaultEvent; import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; ...

    Flex Olap完整项目源码,可直接运行

    <mx:VDividedBox id="mainbox" width="100%" height="100%" x="10" y="10" creationComplete="addListeners()"> <mx:ViewStack id="viewStack" width="100%" height="75%" creationComplete="showData()" change...

    flex实列demo

    *" creationComplete="initTree(); iFrame.visible=true" viewSourceURL="srcview/index.html"> change="iFrame.source=tree.selectedNode.path" /> <![CDATA[ import mx....

    Actionscript与javascript交互实例程序(修改)

    mxml页面: <?xml version=1.0 encoding=utf-8?> xmlns:s spark xmlns:mx=library://ns.adobe.com/flex/mx width height=100% xmlns:code=http://code.google.com/p/flex-iframe/ creationComplete> <f

    adobe-edge-xml-arabic:基本符号示例(带有阿拉伯文本的 Edge Animate)交互性向您展示如何加载和显示 XML

    代码示例/事件 > creationComplete var 消息; $.ajax({ type: "GET", url: "edit.xml", dataType: "xml", success: function (xml) { $(xml).find('edit').each(function () { var sTitle = $(this).find...

    flash+xml超酷欧美FLASH整站源码

    creationComplete="service.send()" > <![CDATA[ import mx.controls.Alert; import mx.rpc.events.FaultEvent; import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; ...

    my test just a test

    creationComplete="init()"> [A-Z,0-9]" validator="{fltNoValidator}"/> [A-Z,0-9]" text="{this.formatDate(new Date)}" validator="{fltDateValidator}" /> ...

Global site tag (gtag.js) - Google Analytics