posts - 17, comments - 4, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          [原]自定義組件的屬性與事件

          Posted on 2007-08-28 12:07 愚人 閱讀(210) 評論(0)  編輯  收藏 所屬分類: Flex2
          在開發(fā)Flex程序后經(jīng)常會使用到自定義組件,通過設(shè)置它的屬性來初始化一些值,最經(jīng)常用到的就是自定義事件與屬性了,當然還有方法。對于自定義事件可以在元數(shù)據(jù)標簽中加入[Event(name="Login", type="flash.events.Event")]聲明一個組件的事件,既然聲明了肯定就有一個能夠用來觸發(fā)的事件,使用dispatchEvent(new Event("Login"))來分發(fā)時間。對于屬性直接聲明一個公有的屬性即可,方法也是一樣。

           1<?xml version="1.0" encoding="utf-8"?>
           2<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="275" height="150" title="untitled">
                     <!-- 使用原數(shù)據(jù)標簽聲明一個事件Login,類型為flash.events.Event -->
           3    <mx:Metadata>
           4        [Event(name="Login", type="flash.events.Event")]
           5    </mx:Metadata>
           6    <mx:Script>
           7        <![CDATA[
                            //聲明為public屬性之后,就變成了組件的公有屬性了
           8            [Bindable]
           9            public var upitem:String="";
          10            [Bindable]
          11            public var downitem:String="";
          12            [Bindable]
          13            public var eafterclk:Boolean = false ;
          14            private function handleLoginEvent():void
          15            {
          16                txtUID.editable = eafterclk ;
          17                txtPwd.editable = eafterclk ;
          18                lblTest.htmlText = "<b>logging in</b>" ;
          19                //分發(fā)事件Login
          20                dispatchEvent(new Event("Login"));
          21            }
          22        ]]>
          23    </mx:Script>
          24    <mx:Model id="login">
          25        <user>
          26            <name>{txtUID.text}</name>
          27            <password>{txtPwd.text}</password>
          28        </user>
          29    </mx:Model>
          30    <mx:Label x="10" y="12" text="{upitem}"/>
          31    <mx:Label x="10" y="42" text="{downitem}"/>
          32    <mx:TextInput x="74" y="10" id="txtUID"/>
          33    <mx:TextInput x="74" y="40" id="txtPwd" displayAsPassword="true"/>
          34    <mx:Button x="178" y="70" label="Login" click="handleLoginEvent()"/>    
          35    <mx:Label x="74" y="72" id="lblTest"/>
          36</mx:Panel>





           1<?xml version="1.0" encoding="utf-8"?>
           2<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientColors="[#804000, #ffffff]" xmlns:ns1="*">
           3    <mx:states>
           4        <mx:State name="t">
           5            <mx:RemoveChild target="{user}"/>
           6            <mx:AddChild position="lastChild">
           7                <mx:ProgressBar maximum="100" minimum="0" enabled="true" labelPlacement="center" horizontalCenter="0" verticalCenter="0"/>
           8            </mx:AddChild>
           9            <mx:AddChild position="lastChild">
          10                <mx:HBox width="195" right="2" top="2">
          11                    <mx:Image right="84" top="10" source="file:///D|/www/images/icon_acct_active.gif"/>
          12                    <mx:Label text="Welcome,{user.login.name}" color="#ffffff" right="22" top="10"/>
          13                </mx:HBox>
          14            </mx:AddChild>
          15        </mx:State>
          16    </mx:states>
          17    <mx:Script>
          18        <![CDATA[
          19            import mx.controls.Alert ;
          20            public function login():void{
          21                if( user.login.name == "Fisher" )
          22                {
          23                    //Alert.show("User:"+user.login.name+"\n\nPass:******","Login");
          24                    this.currentState = "t";
          25                }
          26            }
          27        ]]>
          28    </mx:Script>
          29    <ns1:LoginBox title="LOGIN" upitem="Username" eafterclk="true" downitem="Password" id="user" y="181" horizontalCenter="0" Login="login()">
          30    </ns1:LoginBox>
          31    
          32</mx:Application>

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 宾阳县| 天长市| 二连浩特市| 湘乡市| 礼泉县| 响水县| 舞钢市| 乐至县| 萨嘎县| 泸西县| 唐海县| 平利县| 神木县| 徐闻县| 栖霞市| 宣武区| 灵武市| 武隆县| 文安县| 华坪县| 舒兰市| 祥云县| 娱乐| 普宁市| 黔南| 封开县| 三原县| 饶河县| 美姑县| 张家川| 公主岭市| 大渡口区| 临夏市| 绿春县| 广汉市| 达州市| 驻马店市| 长沙县| 丰顺县| 遂平县| 山东省|