怎样区别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了)的次优先级的所有监听都不执行
相关文章推荐
- js中的stopImmediatePropagation方法和stopPropagation方法的区别
- e.stopPropagation 与 e.stopImmediatePropagation的区别
- Flex事件流中有关 【 stopImmediatePropagation()和stopPropagation()】 的区别
- W3C/JQuery中stopImmediatePropagation和stopPropagation的区别
- js中preventDefault 与stopPropagation 及 stopImmediatePropagation的区别
- AS3 event stopImmediatePropagation() stopPropagation()用法以及区别
- stopImmediatePropagation 和stopPropagation的区别
- jQuery 事件中stoppropagation和stopimmediatepropagation的区别
- (转)stopImmediatePropagation 和stopPropagation的区别
- stopImmediatePropagation&stopPropagation 区别
- 事件的stopImmediatePropagation和stopPropagation
- Event的stopImmediatePropagation和stopPropagation方法
- jQuery源码分析之jQuery.Event,$.stopImmediatePropagation,$.preventDefault,$.stopPropagation
- 事件的stopImmediatePropagation和stopPropagation
- AS3 event flow 事件冒泡机制 以及 stopImmediatePropagation() stopPropagation()用法
- AS3 event flow 事件冒泡机制 以及 stopImmediatePropagation() stopPropagation()用法 及useCapture的用法
- AS3 event flow 事件冒泡机制 以及 stopImmediatePropagation() stopPropagation()用法
- stopPropagation与stopImmediatePropagation
- click点击一次触发多次,冒泡与阻止冒泡,event.stopPropagation()和event.preventDefault(),return false三种的区别