麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發 > Flex > 正文

關于Flex 初始化的research

2024-09-12 17:51:28
字體:
來源:轉載
供稿:網友
后來研究發現,不是取不到,而是在createChildren的時候,自定義的objcet還沒有被賦值,只有當該組件的init事件之后才會被賦值,代碼如下:
APP:
復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute" xmlns:com="com.*">
    <mx:Script>
        <!--[CDATA[
            [Bindable]
            private var o:Object = {};
        ]]-->
    </mx:Script>
    <com:CustomPanel width="100%" height="100%" label="FlexInitResearch">
        <com:CustomButton label="Button"
            customString="customString test" customObject="{o}"/>
    </com:CustomPanel>
</mx:Application>

CustomPanel:
復制代碼 代碼如下:

package com
{
    import mx.containers.Panel;
    import mx.events.FlexEvent;

    public class CustomPanel extends Panel
    {
        public 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):void
        {
            trace("CustomPanel[ PreInit ]");
        }

        private function onInit(event:FlexEvent):void
        {
            trace("CustomPanel[ Init ]");
        }

        private function onCreationComplete(event:FlexEvent):void
        {
            trace("CustomPanel[ CreationComplete ]");
        }

        private function onAppInitComplete(event:FlexEvent):void
        {
            trace("CustomPanel[ AppInitComplete ]");
        }

        //=================================
        // override function
        //=================================

        override protected function createChildren():void
        {
            trace("CustomPanel[ Begin to createChildren ]");
            super.createChildren();
            trace("CustomPanel[ The end of createChildren ]");
        }

        override protected function measure():void
        {
            trace("CustomPanel[ Begin to measure ]");
            super.measure();
            trace("CustomPanel[ The end of measure ]");
        }

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            trace("CustomPanel[ Begin to updateDisplayList ]");
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            trace("CustomPanel[ The end of updateDisplayList ]");
        }

        override protected function layoutChrome(unscaledWidth:Number, unscaledHeight:Number):void
        {
            trace("CustomPanel[ Begin to layoutChrome ]");
            super.layoutChrome(unscaledWidth, unscaledHeight);
            trace("CustomPanel[ The end of layoutChrome ]");
        }

        override protected function commitProperties():void
        {
            trace("CustomButton[ Begin to commitProperties ]");
            super.commitProperties();
            trace("CustomButton[ The end of commitProperties ]");
        }
    }
}

CustomButton:
復制代碼 代碼如下:

package com
{
    import 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():String
        {
            return _customString;
        }
        //string
        public function set customString(value:String):void
        {
            trace("CustomButton( set customString )");
            _customString = value;
        }

        //object
        public function get customObject():Object
        {
            return _customObject;
        }

        public function set customObject(value:Object):void
        {
            trace("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):void
        {
            trace("CustomButton( PreInit )");
        }

        private function onInit(event:FlexEvent):void
        {
            trace("CustomButton( Init )");
        }

        private function onCreationComplete(event:FlexEvent):void
        {
            trace("CustomButton( Creation Complete )");
        }

        private function onAppInitComplete(event:FlexEvent):void
        {
            trace("CustomButton( AppInitComplete )");
        }

        //=================================
        // override function
        //=================================

        override protected function createChildren():void
        {
            trace("CustomButton( Begin to createChildren )");
            super.createChildren();
            trace("CustomButton( The end of createChildren )");
        }

        override protected function measure():void
        {
            trace("CustomButton( Begin to measure )");
            super.measure();
            trace("CustomButton( The end of measure )");
        }

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            trace("CustomButton( Begin to updateDisplayList )");
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            trace("CustomButton( The end of updateDisplayList )");
        }

        override protected function commitProperties():void
        {
            trace("CustomButton( Begin to commitProperties )");
            super.commitProperties();
            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改成如下,發現跟預想中的一樣,最后的輸出結果與上面的一樣:
復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute" xmlns:com="com.*">
    <mx:Script>
        <!--[CDATA[
            [Bindable]
            private var o:String = "String test";//將原對象換成字符串
        ]]-->
    </mx:Script>
    <com:CustomPanel width="100%" height="100%" label="FlexInitResearch">
        <com:CustomButton label="Button"
            customString="customString test" customObject="{o}"/>
    </com:CustomPanel>
</mx:Application>

為了進一步確定是由于綁定造成的賦值時期不一致,我又做了如下的一個試驗,不使用綁定給對象變量賦值:
復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute" xmlns:com="com.*">
    <com:CustomPanel width="100%" height="100%" label="FlexInitResearch">
        <com:CustomButton label="Button"
            customString="customString test">
            <com:customObject>
                <mx:ArrayCollection/>
            </com:customObject>
        </com:CustomButton>
    </com:CustomPanel>
</mx:Application>

其結果為:
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 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 ]
CustomPanel[ The end of updateDisplayList ]
CustomButton( Begin to updateDisplayList )
CustomButton( The end of updateDisplayList )
CustomButton( Creation Complete )
CustomPanel[ CreationComplete ]
問題確定,所以以后再createChildren 中使用自定義對象變量的時候必須要注意,否則就會出現空指針之類的問題了。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黄色7777| 欧美性受ⅹ╳╳╳黑人a性爽 | 天堂成人国产精品一区 | 国产成人在线网址 | 国产亚洲综合一区二区 | 国产免费永久在线观看 | 色成人在线 | 午夜精品成人 | 日韩视频在线不卡 | 欧美雌雄另类xxxxx | 久久激情免费视频 | 日本精品中文字幕 | 中文字幕在线观看精品 | 韩毛片 | 国产精品久久av | av国产免费 | 深夜福利久久久 | 欧美一级成人一区二区三区 | 婷婷久久青草热一区二区 | 99视频网 | 精品爱爱 | 亚洲成人在线免费 | 成人在线视频免费 | chinese18 xxxx videos| av成人免费观看 | 伊人亚洲精品 | 久久久久久久久久久久久久av | 欧美一级精品片在线看 | 综合网日日天干夜夜久久 | 国产免费一区 | 欧美日韩在线播放一区 | 特一级黄色毛片 | 国产精品麻豆一区二区三区 | 久久99国产伦子精品免费 | 久久国产综合精品 | 国产午夜亚洲精品午夜鲁丝片 | 成人宗合网 | 国产精品久久久久久久久久10秀 | 在线成人免费观看 | 毛片大全 | 婷婷一区二区三区四区 |