Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 87158

Confused by stopPropagation()

$
0
0

Hoping, first, that I'm just making a silly mistake or, if not, to better understand what it means to stopPropagation() on an event.

 

Consider this snippet:

 

var beforeCloseListenerTest = app.addEventListener("beforeClose", beforeCloseListenerTest);

 

function beforeCloseListenerTest(beforeCloseEvent) {

    if (beforeCloseEvent.target.constructor.name == "LayoutWindow") { // first beforeClose event

        alert("Layout Window is closing. Propagation will be stopped.");

        beforeCloseEvent.stopPropagation();

    } else {

        alert(beforeCloseEvent.target.constructor.name + " is closing.");

    } // end if

} // end function

 

So, when this event listener is running and a document is closed, the alert is displayed saying that the Layout Window is closing. As expected. But the second alert also displays when the Document closes. My brain is stuck on the idea that stopPropagation() should prevent that.

 

The real event-listener handlers that I'm using all run before the Layout Window closes. It's certainly not a big deal to check the target.constructor,name before deciding whether to do something, but I'm thinking that these scripts would be slightly more efficient if they just stopped at that point.


Viewing all articles
Browse latest Browse all 87158

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>