从 ItemRenderer 组件(图像)内部调用 clickHandler
我正在使用一个 Datagrid,它有一个包含图像的 itemRenderer:
protected static function hbox1_clickHandler(event:MouseEvent):void
{
//some action
}
<mx:DataGrid id="reportDG" dataProvider="{CDODReportsModel.instance.reportDataArrayCollectionObject}" color="black" horizontalScrollPolicy="on">
<mx:columns>
<mx:DataGridColumn headerText="info">
<mx:itemRenderer>
<fx:Component>
<mx:HBox horizontalAlign="center">
<mx:Image source="assets/images/i_info.png" scaleX="0.6" scaleY="0.6" click="hbox1_clickHandler(event)"/>
</mx:HBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="NAME" headerText="NAME"/>
<mx:DataGridColumn dataField="TOTAL" headerText="TOTAL"/>
</mx:columns>
</mx:DataGrid>
我想在单击时调度一个事件,因此当我单击图像时我会执行一个操作。但是,这样做时它给了我一个错误。我做了一些搜索,建议的答案是使用 externalDocument 和 ParentDoecument .. 两者都不起作用。
如何访问点击处理函数(我的代码中的 hbox1_clickHandler() )?
I'm using a Datagrid which has an itemRenderer that contains an image :
protected static function hbox1_clickHandler(event:MouseEvent):void
{
//some action
}
<mx:DataGrid id="reportDG" dataProvider="{CDODReportsModel.instance.reportDataArrayCollectionObject}" color="black" horizontalScrollPolicy="on">
<mx:columns>
<mx:DataGridColumn headerText="info">
<mx:itemRenderer>
<fx:Component>
<mx:HBox horizontalAlign="center">
<mx:Image source="assets/images/i_info.png" scaleX="0.6" scaleY="0.6" click="hbox1_clickHandler(event)"/>
</mx:HBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="NAME" headerText="NAME"/>
<mx:DataGridColumn dataField="TOTAL" headerText="TOTAL"/>
</mx:columns>
</mx:DataGrid>
I want to dispatch an event on click, so when I click on the image I do an action. However, It is giving me an error when do that. I did some search and the suggested answers were using outerDocument and ParentDoecument .. both didn't work.
How can I access the click handler function (hbox1_clickHandler() in my code) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为如果您在应用程序类中这是不可能的。
如果这是其他类,那么您可以编写如下内容:
此外,这不是编写内联项目渲染的最佳主意。最好的方法是扩展基本项目渲染器并制作您自己的渲染器。您还可以扩展 flash 事件类并创建您自己的事件类。这样做使您可以随事件发送一些附加数据。
但无论如何,使用你的方法代码将是这样的:
I dont think that this is possible if you are in Application class.
If this is some other class, than you can just wright something like this:
Also this is not the best idea to wright inline item renderes. The best approach is to extend base item Renderer and make your own one. Also you can extend flash Event class and make your own. Doing this gives you possibility to send some additional data with your event.
But anyway, using yours approach code will be like this:
只要该函数声明为“public”,它就可以与 externalDocument.functionName 一起使用。就您而言,如果您将函数声明从 protected 更改为 public,它将起作用。这是示例代码[工作]:
It will work with outerDocument.functionName as long as the function is declared as 'public'. In your case, if you change your function declaration from protected to public, it will work. Here is the sample example code [working]: