By doing it with the click event on the child you are tight coupling the child to the parent.
By using the bubbling event you are loose coupling and free to use the component anywhere. If you are comfortable with tight coupling, by all means use it. My own preference is to use loose coupling and respond to events as and when I need to. Sometimes it is useful to have multiple parent components in the chain respond to an event at different levels. I stop the propagation once the final component has handled the event. --- In [email protected], Angelo Anolin <angelo_ano...@...> wrote: > > Valdhor, > > Wouldn't it be enough to set the click event on the appButtonComponent's MXML > declaration, like: > > click="myButtonComp onent_Click( event)" > > I think I am missing a point here but could you please elaborate further why > you would do so in your example? > > Thanks a lot. > > Angelo > > > > ________________________________ > From: valdhor <valdhorli...@...> > To: [email protected] > Sent: Fri, 16 April, 2010 10:16:34 > Subject: [flexcoders] Re: MXML Component Call Event in Parent > >  > I would still be inclined to set an event listener in the parent... > > <?xml version="1.0" encoding="utf- 8"?> > <mx:Application xmlns:mx="http: //www.adobe. com/2006/ mxml" >    xmlns:appButtonComp onent="*" >    layout="vertical" >    initialize=" init();" >    verticalScrollPolic y="off" >    horizontalAlign= "left"> >    <mx:Script> >       <![CDATA[ >          import flash.events. Event; >          import mx.controls. Alert; >            >            private function init():void >            { >               addEventListener( MouseEvent. CLICK, > handleMouseEvent) ; >            } > >          private function handleMouseEvent( event:MouseEvent > ):void >          { >             event.stopImmediate Propagation( ); >             Alert.show(" Button Clicked", event.target. > label); >          } >       ]]> >    </mx:Script> >    <appButtonComponent: ButtonComponent id="myButtonCompone nt"/> > </mx:Application> > > > --- In flexcod...@yahoogro ups.com, Angelo Anolin <angelo_anolin@ ...> wrote: > > > > Hi Valdhor, > > > > Thanks for the advice. > > > > I have created a sample button component and a parent component to > > implement this. > > > > Parent.mxml > > <?xml version="1.0" encoding="utf- 8"?> > > <mx:Application xmlns:mx="http: //www.adobe. com/2006/ mxml" > > ààààxmlns:appButtonComp onent="*" > > ààààlayout="vertical" > > ààààinitialize=" init();" > > ààààverticalScrollPolic y="off" > > ààààhorizontalAlign= "left"> > > à<mx:Script> > > àà<![CDATA[à> > àààimport flash.events. Event; > > ààà> > àààprivate function myButtonComponent_ Click(evt: Event) :void > > ààà{ > > ààààAlert.show(" Button Clicked", evt.target.label) ; > > ààà} > > ààà]]> > > à</mx:Script> > > à> > à<appButtonComponent: ButtonComponent id="myButtonCompone nt" > > click="myButtonComp onent_Click( event)"/> > > </mx:Application>à> > > > > > ButtonComponent. mxml > > <?xml version="1.0" encoding="utf- 8"?> > > <mx:HBox xmlns:mx="http: //www.adobe. com/2006/ mxml" verticalAlign= > > "middle" horizontalAlign= "left" horizontalGap= "2" height="50">à> > à<mx:Script> > > àà<![CDATA[ > > àà]]> > > à</mx:Script> > > à> > à<mx:Button id="btn1" label="Button 1" width="100" /> > > à<mx:Button id="btn2" label="Button 2" width="100" /> > > </mx:HBox>à> > > > Clicking on any button on the component will display the label of the > > button which was clicked. > > > > I wonder if I am doing things the "RIGHT" way through this? Although I > > believe I achieved what I wanted to do through this means. I would only > > then use a switch statement and process the necessary method or function > > based on the button which was clicked. > > > > Any further advice and better methods of coding would be highly appreciated. > > > > Thanks, > > > > Angelo > > > > > > > > > > ____________ _________ _________ __ > > From: valdhor valdhorlists@ ... > > To: flexcod...@yahoogro ups.com > > Sent: Thu, 15 April, 2010 13:48:04 > > Subject: [flexcoders] Re: MXML Component Call Event in Parent > > > > à> > I don't really have any simple examples. > > > > I did look at the documentation for the Button Class (http://livedocs. > > adobe.com/ flex/3/langref/ flash/display/ InteractiveObjec t.html#event: > > click) and noted the bubbles property is set to true so the button click > > should bubble up to your parent component. > > > > So, add an event listener in the parent component to catch the event. If > > you have multiple buttons, you will have to check the event.target property > > to find out which button dispatched the event (hint: Add a breakpoint in > > your handler and check the event.target and event.currenttarget properties). > > > > --- In flexcod...@yahoogro ups.com, Angelo Anolin <angelo_anolin@ ...> > > wrote: > > > > > > Hi Valdhor, > > > > > > Care to show some examples? Or some links? Thanks. > > > > > > Angelo > > > > > > > > > > > > > > > ____________ _________ _________ __ > > > From: valdhor <valdhorlists@ ...> > > > To: flexcod...@yahoogro ups.com > > > Sent: Thu, 15 April, 2010 12:14:11 > > > Subject: [flexcoders] Re: MXML Component Call Event in Parent > > > > > > Ãâà> > > Make sure the event is set to bubble. Once it has, the event should > > > bubble up the chain to the parent where an event listener should catch it. > > > > > > --- In flexcod...@yahoogro ups.com, Angelo Anolin <angelo_anolin@ ...> > > > wrote: > > > > > > > > Hi FlexCoders, > > > > > > > > I have created a component consisting of some buttons which I am using > > > > in another MXML component. > > > > > > > > How would I trigger from the parent component an event which was done > > > > inside the component.ÃâàFor example, I clicked on a button on > > > > the component which I embedded, that should map to an event on the > > > > parent containing the component. > > > > > > > > I am looking to reuse the same component in other MXML files as well. > > > > > > > > Thanks. Appreciate your inputs. > > > > > > > > Regards, > > > > > > > > Angelo > > > > > > > > > >

