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 <[email protected]> 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 > > > > > >

