Flex中itemRenderer的使用简介

itemRenderer渲染器在Flex应用中是相当重要的,它能够丰富List等容器的样式,将默认为label的<mx:List>中能够加入<mx:Image/><mx:But同/>等标签。
如下图所示:
[img]http://dl.iteye.com/upload/attachment/353285/49132eda-9d36-3e82-b835-895bc9d5bad9.png[/img]

这样<mx:List/>显示的内容更加丰富了。

那么如何操作渲染器中的元素们呢?例如点击上图中的“删除”(图片),将本条item删除。
尅通过在<mx:itemRenderer/>中的<mx:Image/>标签上添加事件来完成,

例如:
<mx:Image source="image/del.png" click="this.parentDocument.showMe(event)"/>
这样就可以到用到外部的showMe()方法了。
如果想通过这个<mx:Image/>标签传递值可以用一下方法


<mx:Script>
<![CDATA[
[Bindable]
[Embed(source="image/stop.png")]
private var stop:Class;

[Bindable]
[Embed(source="image/play.png")]
private var play:Class;

private function showMe(event:MouseEvent):void{
Alert.show((event.currentTarget as Image).data.toString());
}

]]>

<mx:XML id="tempXML">
<root>
<name>sdfaasdfadfd</name>
</root>
<root>
<name>oooooooo</name>
</root>
</mx:XML>


<mx:List dataPrivoder="{tempXML.root}">
<mx:itemRenderer>
<mx:Component>
<mx:Image source="{this.parentDocument.stop}"
data="{data.name}"
click="this.parentDocument.showMe(event)"/>
</mx:Component>
</mx:ItemRenderer>
</mx:List>

注意: <mx:Image/>标签中是通过data="{data.name}"来存储值的
路径source="{this.parentDocument.stop}"通过this.parentDocument来调用外部绑定的图片。
点击事件 click同理。
下附代码:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值