谢谢你,乔尔。这是我读了那篇文章(我以前读过)后提出的最终解决方案。我想将其按钮被单击的项目添加到另一个项目的属性数组中,因此我将“其他项目”作为属性传递到DataGrid组件中,并在itemRenderer的函数调用中对其执行操作:
/* CustomDataGrid.mxml */
<mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
public var otherData:Object;
public function takeAction(item:Object):void
{
otherData["children"][0] = item;
}
]]>
</mx:Script>
<mx:columns>
<mx:DataGridColumn dataField="firstName" headerText="First Name"
width="75" />
<mx:DataGridColumn dataField="LastName" headerText=" Last Name"
width="150" />
<mx:DataGridColumn dataField="phone" headerText="Phone"
width="120" />
<mx:DataGridColumn headerText="" width="110"
itemRender="ActionButtonItemRenderer" />
</mx:columns>
</mx:DataGrid>
/* ActionButtonItemRenderer.as */
package
{
import flash.events.MouseEvent;
import mx.controls.Button;
public class ActionButtonItemRenderer extends Button
{
public function ActionButtonItemRenderer()
{
super();
label = "Take Action";
}
override protected function clickHandler(event:MouseEvent):void
{
super.clickHandler(event);
var owner:CustomDataGrid = listData.owner as CustomDataGrid;
owner.takeAction(data);
}
}
}