-------------- MyEvent.as ---------------
package
{
import flash.events.Event;
public class MyEvent extends Event{
public var name:String;
public var address:String;
public static const DATA_TRANSFER:String = "data_transfer";
public function MyEvent(type:String, bubbles:Boolean,
cancelable:Boolean, name:String, address:String){
super(type, bubbles, cancelable)
this.name = name;
this.address = address;
}
override public function clone():Event {
return new MyEvent(type, bubbles, cancelable, name, address);
}
}
}
-------------- MyPanel.mxml ---------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml"
width="400" height="300" creationComplete="init();">
<mx:Script>
<![CDATA[
import MyEvent;
private function init():void{
systemManager.addEventListener(MyEvent.DATA_TRANSFER,
handleDataTransfer, true);
}
private function handleDataTransfer(evt:MyEvent):void{
this.lblName.text = evt.name;
this.lblAddress.text = evt.address;
}
]]>
</mx:Script>
<mx:HBox>
<mx:Label text="Name: "/>
<mx:Label id="lblName"/>
</mx:HBox>
<mx:HBox>
<mx:Label text="Address: "/>
<mx:Label id="lblAddress"/>
</mx:HBox>
</mx:Panel>
-------------- MainApp.mxml ---------------
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:comp="*">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import MyEvent;
[Bindable] private var aCollection:ArrayCollection = new
ArrayCollection([
{name: "name1", address: "address1"},
{name: "name2", address: "address2"},
{name: "name3", address: "address3"}
]);
private function changeHandler(evt:Event):void{
var myEVT:MyEvent = new MyEvent(MyEvent.DATA_TRANSFER, false, true,
evt.currentTarget.selectedItem.name,
evt.currentTarget.selectedItem.address);
this.dispatchEvent(myEVT);
}
]]>
</mx:Script>
<mx:DataGrid dataProvider="{aCollection}" change="changeHandler(event)">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="Name" />
<mx:DataGridColumn dataField="address" headerText="Address" />
</mx:columns>
</mx:DataGrid>
<comp:MyPanel/>
</mx:Application>
simple example using custom events... we can pass data to action script and
get data from as file also...
like this any one have singleton procedure
Prajnith
On Fri, Oct 30, 2009 at 8:05 PM, flexorz group of flex corders <
[email protected]> wrote:
> there are sevaral ways to archieve this ,
>
> 1) would be to have a variable in a the parent and one component can change
> it and other can refer
> 2) use model (singlton intance for data as you do in cairngrom ,purmvc)
> 3) use a event to pass the data along
> 4)have reference of the componet you want to use
>
> but all these are dependent on your componet structure
> so with out knowing the component layout its hard to let you know what is
> the best method to do so.
>
> Dinukx
>
>
>
>
>
>
> On Fri, Oct 30, 2009 at 5:12 PM, prajnith K <[email protected]> wrote:
>
>> hi friends can we pass a string or text value form one component to
>> another..?
>>
>> if" can u tell me how?
>> Prajnith
>>
>>
>>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex
India Community" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---