views:

516

answers:

1

I have a datagrid with a custom label itemrenderer (basically it makes the label look like a traditional html hyperlink).

<mx:DataGridColumn id="itemId">  
  <mx:itemRenderer>
    <mx:Component>
      <controls3:HyperlinkLabel text="{data.doc}" />
    </mx:Component>
  </mx:itemRenderer>   
</mx:DataGridColumn> 

The above works perfectly.

I'd like to try add an event listener to this itemrenderer, but I'm not sure how to do this given that I cant specify an id for the itemrendered itself.

I tried the following, but it doesnt seem to work:

itemId.addEventListener(MouseEvent.CLICK, onItemSelect);
+1  A: 

You don't need an ID. Just do it using event.currentTarget

<mx:DataGridColumn id="itemId">  
  <mx:itemRenderer>
    <mx:Component>
      <controls3:HyperlinkLabel text="{data.doc}" click="onItemSelect(event)" />
    </mx:Component>
  </mx:itemRenderer>   
</mx:DataGridColumn> 

And then ... up in your Script tag ...

private function onItemSelect(event:MouseEvent) : void {
 // do something with event.currentTarget
}
Robusto
I dont think that is possible. Firstly, my understanding is that if I wanted to use that method, it would be outerDocument.onItemSelect(event)But I really wanted to try use an eventlistener if at all possible, since my code is all in a mediator.
JonoB
Then I have to ask why you are putting presentation markup in a mediator?
Robusto
I'm not sure I understand your question, but for now I've gone with using the outerDocument.onItemSelect(event) method. Its breaks encapsulation, but hey, you gotta do what you gotta do.Thanks for the help.
JonoB