<?
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():void{
canvas1.addEventListener(MouseEvent.CLICK,CanvasHandler);
canvas2.addEventListener(MouseEvent.CLICK,CanvasHandler);
btn1.addEventListener(MouseEvent.CLICK,pressBtn); //因为都没有打开捕获功能,所以输出时从下往上。
btn2.addEventListener(MouseEvent.CLICK,pressBtn,true);
//btn2打开了事件捕获功能,所以输出时从上向下,又因为CanvasHandler函数中有stopImmediatePropagation(),所以到这执行不下去。
}
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("------------");
}
internal function CanvasHandler(event:MouseEvent):void{
output("目标对象---"+event.target+"----"+event.eventPhase);
event.stopImmediatePropagation(); //停止事件流的传播
}
]]>
</ 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 >
< mx:Application xmlns:mx ="http://www.adobe.com/2006/mxml" layout ="absolute" creationComplete ="initApp()" >
< mx:Script >
<![CDATA[
import flash.events.MouseEvent;
internal function initApp():void{
canvas1.addEventListener(MouseEvent.CLICK,CanvasHandler);
canvas2.addEventListener(MouseEvent.CLICK,CanvasHandler);
btn1.addEventListener(MouseEvent.CLICK,pressBtn); //因为都没有打开捕获功能,所以输出时从下往上。
btn2.addEventListener(MouseEvent.CLICK,pressBtn,true);
//btn2打开了事件捕获功能,所以输出时从上向下,又因为CanvasHandler函数中有stopImmediatePropagation(),所以到这执行不下去。
}
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("------------");
}
internal function CanvasHandler(event:MouseEvent):void{
output("目标对象---"+event.target+"----"+event.eventPhase);
event.stopImmediatePropagation(); //停止事件流的传播
}
]]>
</ 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 >