flex初始化reasearch.doc_第1页
flex初始化reasearch.doc_第2页
flex初始化reasearch.doc_第3页
flex初始化reasearch.doc_第4页
flex初始化reasearch.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

尊重版权:/actruel/program/20110913/flex-research.html后来研究发现,不是取不到,而是在createChildren的时候,自定义的objcet还没有被赋值,只有当该组件的init事件之后才会被赋值,代码如下:APP:复制代码 代码如下:CustomPanel:复制代码 代码如下:package comimport mx.containers.Panel;import mx.events.FlexEvent;public class CustomPanel extends Panelpublic function CustomPanel()super();this.addEventListener(FlexEvent.PREINITIALIZE, onPreInit);this.addEventListener(FlexEvent.INITIALIZE, onInit);this.addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete);this.addEventListener(FlexEvent.APPLICATION_COMPLETE, onAppInitComplete);/=/ event handler/=private function onPreInit(event:FlexEvent):voidtrace(CustomPanel PreInit );private function onInit(event:FlexEvent):voidtrace(CustomPanel Init );private function onCreationComplete(event:FlexEvent):voidtrace(CustomPanel CreationComplete );private function onAppInitComplete(event:FlexEvent):voidtrace(CustomPanel AppInitComplete );/=/ override function/=override protected function createChildren():voidtrace(CustomPanel Begin to createChildren );super.createChildren();trace(CustomPanel The end of createChildren );override protected function measure():voidtrace(CustomPanel Begin to measure );super.measure();trace(CustomPanel The end of measure );override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):voidtrace(CustomPanel Begin to updateDisplayList );super.updateDisplayList(unscaledWidth, unscaledHeight);trace(CustomPanel The end of updateDisplayList );override protected function layoutChrome(unscaledWidth:Number, unscaledHeight:Number):voidtrace(CustomPanel Begin to layoutChrome );super.layoutChrome(unscaledWidth, unscaledHeight);trace(CustomPanel The end of layoutChrome );override protected function commitProperties():voidtrace(CustomButton Begin to commitProperties );mitProperties();trace(CustomButton The end of commitProperties );CustomButton:复制代码 代码如下:package comimport mx.controls.Button;import mx.events.FlexEvent;public class CustomButton extends Button/=/ properties/=private var _customString:String = ;private var _customObject:Object = null;public function get customString():Stringreturn _customString;/stringpublic function set customString(value:String):voidtrace(CustomButton( set customString );_customString = value;/objectpublic function get customObject():Objectreturn _customObject;public function set customObject(value:Object):voidtrace(CustomButton( set customObject );_customObject = value;/=/ Constructor/=public function CustomButton()trace(CustomButton( Begin to Constructor );super();this.addEventListener(FlexEvent.PREINITIALIZE, onPreInit);this.addEventListener(FlexEvent.INITIALIZE, onInit);this.addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete);this.addEventListener(FlexEvent.APPLICATION_COMPLETE, onAppInitComplete);trace(CustomButton( The end of Constructor );/=/ event handler/=private function onPreInit(event:FlexEvent):voidtrace(CustomButton( PreInit );private function onInit(event:FlexEvent):voidtrace(CustomButton( Init );private function onCreationComplete(event:FlexEvent):voidtrace(CustomButton( Creation Complete );private function onAppInitComplete(event:FlexEvent):voidtrace(CustomButton( AppInitComplete );/=/ override function/=override protected function createChildren():voidtrace(CustomButton( Begin to createChildren );super.createChildren();trace(CustomButton( The end of createChildren );override protected function measure():voidtrace(CustomButton( Begin to measure );super.measure();trace(CustomButton( The end of measure );override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):voidtrace(CustomButton( Begin to updateDisplayList );super.updateDisplayList(unscaledWidth, unscaledHeight);trace(CustomButton( The end of updateDisplayList );override protected function commitProperties():voidtrace(CustomButton( Begin to commitProperties );mitProperties();trace(CustomButton( The end of commitProperties );最后运行的结果是:CustomPanel PreInit CustomPanel Begin to createChildren CustomButton( Begin to Constructor )CustomButton( The end of Constructor )CustomButton( set customString ) /基本变量(String,Number(int,uint),Boolean)在PreInit 之前就被赋值CustomButton( PreInit )CustomButton( Begin to createChildren )CustomButton( The end of createChildren )CustomButton( Init )CustomButton( set customObject ) /自定义对象变量在 Init之后才能被赋值,所以在createChildren中取不到CustomPanel Init /有子控件的时候,Init 事件是在createChildren中发出的CustomPanel The end of createChildren CustomButton( set customObject )CustomButton Begin to commitProperties CustomButton The end of commitProperties CustomButton( Begin to commitProperties )CustomButton( The end of commitProperties )CustomButton( Begin to measure )CustomButton( The end of measure )CustomPanel Begin to measure CustomPanel The end of measure CustomPanel Begin to updateDisplayList CustomPanel Begin to layoutChrome CustomPanel The end of layoutChrome /证明layoutChrome是在updateDisplayList 中被调用的CustomPanel The end of updateDisplayList CustomButton( Begin to updateDisplayList )CustomButton( The end of updateDisplayList )CustomButton( Creation Complete )CustomPanel CreationComplete 后来又发现,在MXML中设置基本变量和对象变量有一定区别,那就是对象变量必须要用大括号包起来,于是就想,会不会是绑定造成的,将APP改成如下,发现跟预想中的一样,最后的输出结果与上面的一样:复制代码 代码如下:为了进一步确定是由于绑定造成的赋值时期不一致,我又做了如下的一个试验,不使用绑定给对象变量赋值:复制代码 代码如下:其结果为:CustomPanel PreInit CustomPanel Begin to createChildren CustomButton( Begin to Constructor )CustomButton( The end of Constructor )CustomButton( set customString )CustomButton( set customObject ) /赋值时间与基本变量相同CustomButton( PreInit )CustomButton( Begin to createChildren )CustomButton( The end of createChildren )CustomButton( Init )CustomPanel Init CustomPanel The end of createChildren CustomButton Begin to commitProperties CustomButton The end of commitProperti

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论