您的位置:首页 > 运维架构

怎样区别stopPropagation()与stopImmediatePropagation()

2011-05-16 16:55 274 查看
 

 

 

var cont:Sprite = new Sprite();
cont.graphics.beginFill(0xEEEEEE);
cont.graphics.drawRect(0,0,100,80);
cont.graphics.endFill();
addChild(cont);
cont.addEventListener(MouseEvent.MOUSE_DOWN,down);
cont.addEventListener(MouseEvent.MOUSE_UP,up);
var shape:Sprite = new Sprite();
shape.graphics.beginFill(0x000000);
shape.graphics.drawRect(20,20,40,40);
shape.graphics.endFill();
cont.addChild(shape);
shape.addEventListener(MouseEvent.MOUSE_DOWN,downToo,false,2);
shape.addEventListener(MouseEvent.MOUSE_DOWN,downToo2,false,1);
function down(event:MouseEvent):void
{
trace("STOP");

}
function up(event:MouseEvent):void
{
trace("I still can do");
}
function downToo(event:MouseEvent):void
{
trace("I...maybe");
event.stopImmediatePropagation();
}
function downToo2(event:MouseEvent):void
{
trace("I...maybe2");
}


 

先响应shape

另外加了一个监听  stopImmediatePropagation然后再换成stopPropagation 试试就知道区别了

简而言之 stopImmediatePropagation和stopPropagation都能阻挡掉事件流中事件的冒泡

但是stopImmediatePropagation 会让当前对象(不仅parent了)的次优先级的所有监听都不执行
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  function up