This works. Thanks a ton for the example Abdul. Mohanraj
--- Abdul Qabiz <[EMAIL PROTECTED]> wrote: > Hi Mohanraj, > > It's very much possible, I have modified the > previous example to dispatch > events....It would give you some idea, how you can > achieve the same. > > I am using Metadata tag for mxml components, you can > find more about in > docs. > > > ##main.mxml### > > <mx:Application > xmlns:mx="http://www.macromedia.com/2003/mxml" > xmlns="*"> > > <mx:Script> > <![CDATA[ > > var dp:Array = [ > > {label:"Abdul",data:1}, > > {label:"Manish",data:2}, > {label:"Sam", > data:3} > ]; > > > function startListening() > { > //you can also subscribe to change > event of comp1 on this > way... > cmp1.addEventListener("change", > mx.utils.Delegate.create(this, onCMP1Change)); > } > > > > function onCMP1Change(event) > { > cmp2.textValue = > event.target.selectedItem.label; > } > > > > > ]]> > </mx:Script> > > <!-- you can assign event handlers to change > attribute also. Following > lin is commented now../--> > <!-- > <comp id="cmp1" dataProvider="{dp}" > chnage="onCMP1Change(event);"/> > /--> > > <comp1 id="cmp1" dataProvider="{dp}"/> > <comp2 id="cmp2" > creationComplete="startListening();" /> > > </mx:Application> > > > ##comp1.mxml### > > <mx:VBox > xmlns:mx="http://www.macromedia.com/2003/mxml"> > <mx:Metadata> > <!-- this tells the compiler to embed > relevant code, so that you can > broadcast 'change' event /--> > [Event("change")] > </mx:Metadata> > > <mx:Script> > <![CDATA[ > > public var dataProvider:Array; > public var selectedItem:Object; > > > //call this function from change handler of > combobox > and this function dispatches the change event.. > function onSelectionChange(event) > { > selectedItem = event.target.selectedItem; > dispatchEvent({type:'change'}); > } > > ]]> > </mx:Script> > <mx:ComboBox id="_cb" dataProvider="{dataProvider}" > change="onSelectionChange(event);"/> > </mx:VBox> > > > ##comp2.mxml### > > <mx:VBox > xmlns:mx="http://www.macromedia.com/2003/mxml"> > <mx:Script> > <![CDATA[ > > var textValue:String; > > ]]> > </mx:Script> > <mx:TextInput id="_ti" text="{textValue}"/> > </mx:VBox> > > > > About Metadata tag: > http://livedocs.macromedia.com/flex/15/flex_docs_en/00000459.htm > > > Hope that helps... > > -abdul > > > -----Original Message----- > From: Mohanraj Jayaraman > [mailto:[EMAIL PROTECTED] > Sent: Saturday, April 09, 2005 4:13 AM > To: flexcoders@yahoogroups.com > Subject: RE: [flexcoders] Exchanging data between > MXML Components > > > Hi Abdul and Tracy, > > Thanks for the example.It works, but I was expecting > an event driven model instead of binding to exchange > data between components. Can the same be explained > with broadcast/listener model? > > Thanks, > Mohanraj > > > --- Abdul Qabiz <[EMAIL PROTECTED]> wrote: > > Hi, > > > > You can achieve this by using Data Binding in > Flex. > > Did you look at binding? > > > > > > You can bind two controls like this.. > > > > <mx:Application ..> > > > > <mx:ComboBox id="_cb" > dataProvider="[{label:'India', > > data:1}, {label:'USA', > > data:2}]"/> > > <mx:TextInput id="_ta" > > text="{_cb.selectedItem.label}"/> > > > > </mx:Application> > > > > In above code, when combo box selection changes, > > TextArea would be populated > > with selected item's label. > > > > Please look at "Binding and Storing Data in Flex" > > section Flex docs.. > > > http://livedocs.macromedia.com/flex/15/flex_docs_en/wwhelp/wwhimpl/js/html/w > > whelp.htm?href=00000687.htm > > > > > > Another quick-dirty example might give you an some > > idea: > > > > > > ##comp1.mxml### > > > > <mx:VBox > > xmlns:mx="http://www.macromedia.com/2003/mxml"> > > <mx:Script> > > <![CDATA[ > > > > var dataProvider:Array; > > var selectedItem:Object; > > > > ]]> > > </mx:Script> > > <mx:ComboBox id="_cb" > dataProvider="{dataProvider}" > > change="selectedItem = > event.target.selectedItem;"/> > > </mx:VBox> > === message truncated === __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/