user346077
user346077

Reputation:

Access the id of the Button from Datagrird to out side?

I have a button inside the DataGrid using ItemRenderer I want to access the button id inside the click handler. How can I do this?

<fx:Script>
  public function myButton_clickHandler(event:Event):void
  {
    Alert.show("My button was clicked!");
  }
</fx:Script>

<mx:DataGrid width="100%" height="95%" id="id_variableRefList" >
  <mx:columns>
    <mx:DataGridColumn id="id_name" dataField=""/>
    <mx:DataGridColumn id="id_strip" dataField="">
      <mx:itemRenderer>
       <fx:Component>
        <mx:VBox>
         <mx:Button label="My Button" click="outerDocument.myButton_clickHandler(event);" />
        </mx:VBox>
       </fx:Component>
      </mx:itemRenderer>
    </mx:DataGridColumn>
  </mx:columns>
</mx:DataGrid>

I Want to access the My Button id in the click handler.

Upvotes: 1

Views: 133

Answers (1)

alxx
alxx

Reputation: 9897

I suppose you want Button instance, not the id. event.target should be the Button:

public function myButton_clickHandler(event:Event):void
{
   var button:Button = event.target as Button;
   Alert.show("Button " + button.label + " was clicked!");
}

Upvotes: 2

Related Questions