stopPropagation와 stopimmedatePropagation 공통점.
- 둘다 모두 이벤트 전파를 멈추도록 하는 기능임.
- 즉, capture 단계뒤의 이벤트단계인 bubble 단계의 전파를 멈추게함.
틀린점은?
- stopPropagation는 capture단계에 등록되어있는 모든 요소들들을 실행시킨후에 멈춤.
아래와 같이 이벤트가 추가되었을경우
btn_2.addEventListener(MouseEvent.CLICK, this.onBtn2Click);
btn_2.addEventListener(MouseEvent.CLICK, this.onClickTest1);
btn_2.addEventListener(MouseEvent.CLICK, this.onClickTest2);
function onBtn2Click(objEvent:MouseEvent)
{
objEvent.stopPropagation();
}
일때 stopPropagation()메소드가 실행되더라도 onClickTest1(), onClickTest2() 가 실행됨.
- stopImmediatePropagation는 capture단계에 등록되어있는 요소라도 바로 멈춤.
아래와 같이 이벤트가 추가되었을경우
btn_3.addEventListener(MouseEvent.CLICK, this.onBtn3Click);
btn_3.addEventListener(MouseEvent.CLICK, this.onClickTest1);
btn_3.addEventListener(MouseEvent.CLICK, this.onClickTest2);
function onBtn3Click(objEvent:MouseEvent)
{
objEvent.stopImmediatePropagation();
}
일때 stopImmediatePropagation()메소드가 실행되는 시점부터 즉시 멈춤.
[출처] [AS3] test_stopPropagation와 stopimmedatePropagation의 차이점|작성자 딴동네