I have the following code, with events associated to each element. When I click on the radio-button, the onItemClick event belongs to table is executing after onSelect event. I think that is due to table is the parent and rb2 the child.
private function onItemClick(e:ListEvent):void {
selectedRow = parseInt(e.itemRenderer.data.Id)-1;
trace("selectedRow: "+selectedRow);
}
public function selectPoint(event:MouseEvent):void{
trace("selectPoint");
}
<mx:DataGrid id="table" dataProvider="{listCol}"
itemClick="onItemClick(event)">
<mx:columns>
<mx:DataGridColumn id="posibilidades" rendererIsEditor="true"
editorDataField="selected" headerText="Posibilidades" width="100" textAlign="center"
draggable="false" editable="false" resizable="false" sortable="false">
<mx:itemRenderer>
<mx:Component>
<mx:RadioButton name="rb2" label="Punto 2" fontSize="13" enabled="false"
groupName="_rb" value="1" textAlign="center"
preinitialize="event.target.styleName='rbstyle'"
click="outerDocument.selectPoint(event)"
creationComplete="outerDocument.rbCreated(event)"/>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
I need to execute both events in reverse order: onItemClick, and then onSelect.
How can I execute onItemClick before onSelect? I read something about priorities associated to addEventListener, but it didn't work because events are for different components.
EDIT: I'll try to explain my problem and why I'm doing this weird stuff in Flex.
I've a Datagrid component which is updated dynamically by a button called "Add measure". This Datagrid have 4 columns; every measure added to this Datagrid have as a last cell (on 4th column) two radiobuttons.
|-----------------------------------------------------------------------------|
| | | | |
| #1 cell | #2 cell | #3 cell | (o) Radiobutton1 (o) Radiobutton2 |
| | | | |
|-----------------------------------------------------------------------------|
The problem is: when I remove a row, data is removed from display and works fine. But when I add a new one, radio-buttons are reused by Flex and I'm unable to know in which row the new radio-butons are (if Flex reuse them and I remove 3 rows and add a new one, the radio-buttons belongs to this new row can belongs to the last row removed, or another one; it's impossible to assure it).
So, I thought: "OK Fran, maybe you can add an event listener to itemClick in Datagrid, and when the user click on the radio-button, you can know in which row are the radio-button recently clicked (because of itemClick handler)". But Flex didn't execute the handlers in the order that I expected, so I'm really stuck right now.
I'm trying onRollOver event instead of onItemClick and works well, but not always.
callLater(outerDocument.selectPoint, [event])to defer the execution of theselectPointmethod to the next render cycle, but I would strongly advise against it. Perhaps you should rather explain which behaviour you're trying to accomplish so we can help architecture this better. - RIAstar