最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

關(guān)于Flex 初始化的research

 更新時(shí)間:2009年09月28日 18:01:46   作者:  
前些天在寫一個(gè)自定義的UI組件的時(shí)候,發(fā)現(xiàn)在override createChildren的,只能取到基本類型的自定義變量,而取不到Object類型的自定義變量。
后來(lái)研究發(fā)現(xiàn),不是取不到,而是在createChildren的時(shí)候,自定義的objcet還沒(méi)有被賦值,只有當(dāng)該組件的init事件之后才會(huì)被賦值,代碼如下:
APP:
復(fù)制代碼 代碼如下:

<?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:
復(fù)制代碼 代碼如下:

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:
復(fù)制代碼 代碼如下:

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 )");
        }
    }
}

最后運(yùn)行的結(jié)果是:
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 ) //自定義對(duì)象變量在 Init之后才能被賦值,所以在createChildren中取不到
CustomPanel[ Init ] //有子控件的時(shí)候,Init 事件是在createChildren中發(fā)出的
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 中被調(diào)用的
CustomPanel[ The end of updateDisplayList ]
CustomButton( Begin to updateDisplayList )
CustomButton( The end of updateDisplayList )
CustomButton( Creation Complete )
CustomPanel[ CreationComplete ]
后來(lái)又發(fā)現(xiàn),在MXML中設(shè)置基本變量和對(duì)象變量有一定區(qū)別,那就是對(duì)象變量必須要用大括號(hào){}包起來(lái),于是就想,會(huì)不會(huì)是綁定造成的,將APP改成如下,發(fā)現(xiàn)跟預(yù)想中的一樣,最后的輸出結(jié)果與上面的一樣:
復(fù)制代碼 代碼如下:

<?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";//將原對(duì)象換成字符串
        ]]-->
    </mx:Script>
    <com:CustomPanel width="100%" height="100%" label="FlexInitResearch">
        <com:CustomButton label="Button"
            customString="customString test" customObject="{o}"/>
    </com:CustomPanel>
</mx:Application>

為了進(jìn)一步確定是由于綁定造成的賦值時(shí)期不一致,我又做了如下的一個(gè)試驗(yàn),不使用綁定給對(duì)象變量賦值:
復(fù)制代碼 代碼如下:

<?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>

其結(jié)果為:
CustomPanel[ PreInit ]
CustomPanel[ Begin to createChildren ]
CustomButton( Begin to Constructor )
CustomButton( The end of Constructor )
CustomButton( set customString )
CustomButton( set customObject ) //賦值時(shí)間與基本變量相同
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 ]
問(wèn)題確定,所以以后再createChildren 中使用自定義對(duì)象變量的時(shí)候必須要注意,否則就會(huì)出現(xiàn)空指針之類的問(wèn)題了。

相關(guān)文章

  • Flex include和import ActionScript代碼

    Flex include和import ActionScript代碼

    為了讓你的MXML代碼可讀性增強(qiáng),你可以在<mx:Script>標(biāo)簽內(nèi)引用ActionScript代碼文件,而不是把大塊的代碼都插入到<mx:Script>里。引用ActionScript有include和import兩種方式。
    2009-08-08
  • Flex3 界面布局教程 第二篇

    Flex3 界面布局教程 第二篇

    國(guó)慶期間,做了不少基于 flex 的開(kāi)發(fā)工作,對(duì) flex 的布局容器有了進(jìn)一步深入的理解,也找到不少非常棒的文章,分享到這里方便一下大家。
    2009-10-10
  • Flex與.NET互操作 了解FluorineFx的環(huán)境配置(遠(yuǎn)程對(duì)象、網(wǎng)關(guān)、通道、目的地)

    Flex與.NET互操作 了解FluorineFx的環(huán)境配置(遠(yuǎn)程對(duì)象、網(wǎng)關(guān)、通道、目的地)

    Flex中的遠(yuǎn)程對(duì)象訪問(wèn),也就是服務(wù)端提供一個(gè)遠(yuǎn)程服務(wù)對(duì)象(RemotingService Object),在Flex客戶端通過(guò)相應(yīng)的訪問(wèn)技術(shù)去調(diào)用遠(yuǎn)程對(duì)象的過(guò)程。
    2009-06-06
  • Flex 對(duì)象持久化

    Flex 對(duì)象持久化

    總有人問(wèn)我關(guān)于Flex對(duì)象序列化和持久化的問(wèn)題,很多人認(rèn)為對(duì)象不能拷貝到服務(wù)器,其實(shí)淺度的拷貝是可以做到的。
    2009-06-06
  • FLEX是什么及與FLASH的關(guān)系的介紹

    FLEX是什么及與FLASH的關(guān)系的介紹

    FLEX是什么及與FLASH的關(guān)系的介紹...
    2007-02-02
  • 基于Socket的網(wǎng)絡(luò)連接 Flex與.NET互操作(一)

    基于Socket的網(wǎng)絡(luò)連接 Flex與.NET互操作(一)

    Flash/Flex也支持基于Socket的網(wǎng)絡(luò)連接 ,服務(wù)器端可以是C++,VB,C#,Java等任一語(yǔ)言開(kāi)發(fā)。監(jiān)聽(tīng)一個(gè)網(wǎng)絡(luò)端口便可以接收到Flash/Flex開(kāi)發(fā)的客戶端的連接。
    2009-06-06
  • Flex Bindable 的用法

    Flex Bindable 的用法

    什么是元數(shù)據(jù)(metadata):[Bindable]大概又是Flex用得最多的元數(shù)據(jù)了。
    2009-10-10
  • Flex clipContent 編程注意

    Flex clipContent 編程注意

    在做Flex項(xiàng)目的時(shí)候,碰到了一個(gè)修改,具體請(qǐng)看下面的原型圖
    2009-07-07
  • Flex Namespace的用法

    Flex Namespace的用法

    自定義自己組件的namespace呢 去Adobe那邊的compiler參數(shù)查找了一下,發(fā)現(xiàn)可以利用-namespace、-include-namespaces這兩個(gè)參數(shù)來(lái)指定自己的URL。
    2009-07-07
  • flex 手寫在線簽名實(shí)現(xiàn)代碼

    flex 手寫在線簽名實(shí)現(xiàn)代碼

    企業(yè)信息系統(tǒng)中,有時(shí)候需要用到手寫簽名的功能。在這里用flex 實(shí)現(xiàn)一個(gè)。功能實(shí)現(xiàn)了,效果還在改善中。
    2009-08-08

最新評(píng)論

响水县| 尖扎县| 竹溪县| 札达县| 罗定市| 沁源县| 聊城市| 安吉县| 精河县| 阿瓦提县| 利津县| 苍梧县| 崇左市| 阳曲县| 福贡县| 新乡市| 宁明县| 黄陵县| 胶南市| 临海市| 丰都县| 同江市| 会昌县| 广丰县| 余姚市| 普兰店市| 皮山县| 台中市| 叶城县| 威信县| 漳浦县| 黔东| 县级市| 合作市| 长丰县| 神木县| 温宿县| 资源县| 烟台市| 怀宁县| 眉山市|