The problem can be summarized as when clicking an item in datagrid, the text area shows the value of the item, but here the compoents are separate and hence events need to be dispatched.
My mxml component file :
<?xml version="1.0" encoding="utf-8"?>
<mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml" itemClick="itemClickEvent(event);" creationComplete="init()">
<mx:Metadata>
[Event(name="IdSelected", type="one.IdEvent")]
</mx:Metadata>
<mx:Script>
<![CDATA[ import genericReport.*;
import crewUtilization.*;
import utils.*;
import studies.*;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import mx.events.ListEvent;
private function itemClickEvent(event:ListEvent):void
{
var _study:Object=event.currentTarget.selectedItem.study;
dispatchEvent(new IDEvent(_ID));
}
]]>
</mx:Script>
<mx:columns>
<mx:DataGridColumn dataField="name" />
<mx:DataGridColumn dataField="userId" />
</mx:columns>
</mx:DataGrid>
///////////////////////////////////////////////////////////////
This is my Main MXML Application file :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:custom="*">
<mx:TitleWindow label="Scenario Creation" xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:ns1="ccCreation.*">
<mx:Label text="CC CREATION" width="100%" />
<mx:VBox width="100 %" styleName="scenariovboxStyle">
<custom:studySelector id="dg" />
</mx:VBox>
</mx:TitleWindow>
</mx:Application>
I think it might be better for studyId to refer to the dataGrid rather than the dataGrid referring to studyId. You can add this to your main mxml:
This should work because TextArea.text will respond to the property changed event of DataGrid.selectedItem, so it will change whenever the selection changes.
EDIT: Dispatching events:
You can dispatch an event from any place in your code, and listeners will be able to listen in to that event. Eg:
Now you can listen for that event:
Hope this helps!
What happens is whenever a StudyEvent.STUDYSELECTED event is fired from your customComponent, it will be caught by your main function and studySelectedListener will be called.