您的位置:首页 > 移动开发

flex事件处理(三个阶段)

2008-03-26 14:55 316 查看

<?xml version="1.0" encoding="utf-8"?>


<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()">


    <mx:Script>


        <![CDATA[


            import flash.events.MouseEvent;


            internal function initApp(){


                /*


                    addEventListener(type:String ,listener:Function,useCapture:Boolean=false,priority:int=0,useWeakReference:Boolean=false)


                        useCapture  表示是否打开捕获事件,默认为false


                        priority    表示监听器的优先级,默认为0


                        useWeakReference   表示是否使用弱引用,默认为false


                */


                canvas1.addEventListener(MouseEvent.CLICK,pressBtn,true);


                canvas2.addEventListener(MouseEvent.CLICK,pressBtn);


                btn1.addEventListener(MouseEvent.CLICK,pressBtn);


                btn2.addEventListener(MouseEvent.CLICK,pressBtn,true);


            }


            internal function output(msg:String):void{


                txtArea1.text += msg+" ";


            }


            internal function pressBtn(event:MouseEvent):void{


                this.output("是否冒泡---"+event.bubbles);//event.bubbles 表示是否打开冒泡功能


                //输出当前的点击对象和事件流当前的阶段,1表示捕获阶段,2表示目标阶段,3表示冒泡阶段


                this.output("目标对象:"+event.target+":"+event.eventPhase);


                //输出当前正在处理的对象


                this.output("遍历对象:"+event.currentTarget);


                this.output("------------");


            }


        ]]>


    </mx:Script>


    <mx:Canvas x="10" y="10" width="328" height="355" id="canvas1">


        <mx:Text x="21" y="10" text="canvas1" id="txt1"/>


        <mx:Canvas x="10" y="36" width="308" height="135" id="canvas2">


            <mx:Text x="129" y="10" text="canvas2" id="txt2"/>


            <mx:Button x="118" y="55" label="Button2" id="btn2"/>


        </mx:Canvas>


        <mx:Button x="21" y="179" label="Button1" id="btn1"/>


        <mx:TextArea x="10" y="209" width="308" height="136" id="txtArea1"/>


    </mx:Canvas>


</mx:Application>



 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息