Flex Event stopimmediatepropagation VS stoppropagation

Categories: Flex; Tagged with: ; @ June 17th, 2011 17:35

What’s the difference ? Here is the test codes:

We will create a button in a Group, and listen the button click event(MouseEvent.Click):

		protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void {
			//  Create button and container
			var hbox:HGroup = new HGroup();
			var button:Button = new Button();
			button.label = "Button";

			// Add Eventer litener
			button.addEventListener(MouseEvent.CLICK, onButtonClick1);
			button.addEventListener(MouseEvent.CLICK, onButtonClick2);
			hbox.addEventListener(MouseEvent.CLICK, onButtonClick3);

			hbox.addElement(button);
			addElement(hbox);
		}

			// Button click handler 1
			private function onButtonClick1(e:MouseEvent):void {
				e.stopImmediatePropagation(); // or e.stopPropagation();
				trace("Handler 1");
			}

			// Button click handler 2
			private function onButtonClick2(e:MouseEvent):void {
				trace("Handler 2");
			}

			// Button click handler 3 listened by hbox
			private function onButtonClick3(e:MouseEvent):void {
				trace("Handler 3");
			}

Here is the difference:

when use stop propagation in the handler 1st, the trace is:

Handler 1
Handler 2

but when use stopImmediatePropagation(), the trace is:

Handler 1

That’s pretty easy to find the differences:

“The stopImmediatePropagation() method also prevents the Event objects from moving on to the next node, but it does not allow any other event listeners on the current node to execute.” (Adobe livedocs)

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.