Stop event propagation : Event « Event « Flex






Stop event propagation

Stop event propagation
      
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical" creationComplete="initFunc()">
    <mx:Script>
        
        import mx.controls.Alert;
        public function initFunc():void
        {
            myButton.addEventListener("click",respondToEvent,false,100);
            myParentHBox.addEventListener("click",parentEventResponse, false,0);
        }
        public function respondToEvent(e:Event):void{
            var msg:String = "hi";

            Alert.show(msg,"First Event Listener");
            e.stopPropagation();
        }
        public function respondToEventClick(e:Event):void
        {
            Alert.show("fire second ","Second Event Listener");
        }
        public function parentEventResponse(e:Event):void
        {
            Alert.show("You should never see this alert","Parent Event Response");
        }
      
    </mx:Script>
    <mx:HBox id="myParentHBox">
        <mx:Button id="myButton" label="Fire off Event" click="respondToEventClick(event)" />
    </mx:HBox>
</mx:Application>

   
    
    
    
    
    
  








Related examples in the same category

1.Hold down the Shift key while pressing the mouse buttonHold down the Shift key while pressing the mouse button
2.Set the value of the errorString property to create an error tipSet the value of the errorString property to create an error tip
3.Nested inner functionNested inner function
4.Submit button callSubmit button call
5.Add a new button when the user presses an existing buttonAdd a new button when the user presses an existing button
6.Manually dispatch an event in an MXML tagManually dispatch an event in an MXML tag
7.UI Control initialization eventUI Control initialization event
8.Add ActionScript code in the component's definition for initialize eventAdd ActionScript code in the component's definition for initialize event
9.Use dispatchEvent() method to dispatch any eventUse dispatchEvent() method to dispatch any event
10.Dispatch an event in an MXML tagDispatch an event in an MXML tag
11.Create new event from ActionScriptCreate new event from ActionScript
12.Single event property accessSingle event property access
13.Add loading complete event for URLLoader
14.Create Complete event and initialize eventCreate Complete event and initialize event
15.Cast event sender to UI controlCast event sender to UI control
16.Module loading eventModule loading event
17.Using error event when loading ModuleUsing error event when loading Module
18.Handling Events InlineHandling Events Inline
19.Use Event BubblingUse Event Bubbling
20.Bind getter function to phoneNumberChanged eventBind getter function to phoneNumberChanged event
21.NonCommittingChangeEvent DemoNonCommittingChangeEvent Demo
22.NonCommittingChange Event SampleNonCommittingChange Event Sample
23.StartUp event OrderStartUp event Order
24.Event With FunctionEvent With Function
25.Event BubblingEvent Bubbling
26.Set HTMLText With Initialize eventSet HTMLText With Initialize event
27.Get Scrolled position from ScrollEventGet Scrolled position from ScrollEvent
28.Change EventChange Event
29.Using change event to recognize that a new item was entered into the prompt, and adds it to the data providerUsing change event to recognize that a new item was entered into the prompt, and adds it to the data provider
30.Edit Event Prevents EditEdit Event Prevents Edit