我有一个带有自定义itemrenderer的mx:列表。
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%"
horizontalScrollPolicy="off" verticalScrollPolicy="off"
>
<fx:Declarations>
<!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). -->
</fx:Declarations>
<fx:Script>
<![CDATA[
/* part with no warning
[Bindable] var tName:String;
override public function set data(value:Object):void
{
acID.text = value.id;
acGlob.text = value.glob;
acVisiO.text = value.visibO;
acVisiV.text = value.visibV;
acRoot.text = value.root;
//acPhoto.source = value.photo;
//acName.text = value.name;
tName = value.name
}
override public function get data():Object
{
return super.data;
} */
]]>
</fx:Script>
<mx:states>
<mx:State name="normal"/>
<mx:State name="hovered"/>
<mx:State name="selected"/>
</mx:states>
<mx:Image source="{data.photo}" width="20" height="20" alpha.hovered=".5"/>
<mx:Label text="{data.name}"
color.hovered="0x1313cd" color.selected="0x000000" color.normal="#000000"
toolTip="{data.name}"
/>
<mx:Label visible="false" width="0" height="0" id="acID" />
<mx:Label visible="false" width="0" height="0" id="acGlob"/>
<mx:Label visible="false" width="0" height="0" id="acVisiO"/>
<mx:Label visible="false" width="0" height="0" id="acVisiV"/>
<mx:Label visible="false" width="0" height="0" id="acRoot" />
</mx:HBox>
如果我使用设定数据功能,则不会出现警告。但在这种情况下,我不知道如何访问doublickclik上的itemrenderer数据。
arrList = new ArrayList(list);
listAcc = new List();
listAcc.percentHeight = 100;
listAcc.percentWidth =100;
listAcc.itemRenderer = new ClassFactory(irMxList);
listAcc.doubleClickEnabled = true;
listAcc.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, onItemDoubleClick);
listAcc.dataProvider = arrList;
我的问题是,如果我尝试访问itemrenderer.data
,则会出现错误private function onItemDoubleClick(event:ListEvent):void {
var label:String = event.itemRenderer.data.name;
var index:String = event.itemRenderer.data.id;
var glob:String = event.itemRenderer.data.glob;
var visuO:String = event.itemRenderer.data.visibO;
var visuV:String = event.itemRenderer.data.visibV;
var rootFile:String = event.itemRenderer.data.root;
}
感谢您的帮助
答案 0 :(得分:1)
private function onItemDoubleClick(event:ListEvent):void {
var data:Object = arrList.getItemAt(event.rowIndex);
var label:String = data.name;
var index:String = data.id;
var glob:String = data.glob;
var visuO:String = data.visibO;
var visuV:String = data.visibV;
var rootFile:String = data.root;
}
答案 1 :(得分:0)
在下面找到解决方案
private function onItemDoubleClick(event:ListEvent):void {
var label:String = event.itemRenderer.data.name;
var index:String = event.itemRenderer.data.id;
var glob:String = event.itemRenderer.data.glob;
var visuO:String = event.itemRenderer.data.visibO;
var visuV:String = event.itemRenderer.data.visibV;
var rootFile:String = event.itemRenderer.data.root; }
ItemRenderer代码是
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%"
horizontalScrollPolicy="off" verticalScrollPolicy="off"
>
<fx:Declarations>
<!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private var _data:Object;
override public function set data(value:Object):void {
acID.text = value.id;
acGlob.text = value.glob;
acVisiO.text = value.visibO;
acVisiV.text = value.visibV;
acRoot.text = value.root;
acPhoto.source = value.photo;
acName.text = value.name;
_data = value;
}
override public function get data():Object {
return _data;
}
]]>
</fx:Script>
<mx:states>
<mx:State name="normal"/>
<mx:State name="hovered"/>
<mx:State name="selected"/>
</mx:states>
<!--<mx:Image source="{data.photo}" width="20" height="20" alpha.hovered=".5"/>
<mx:Label text="{data.name}"
color.hovered="0x1313cd" color.selected="0x000000" color.normal="#000000"
toolTip="{data.name}"
/>-->
<mx:Image id="acPhoto" width="20" height="20" alpha.hovered=".5"/>
<mx:Label id="acName"
color.hovered="0x1313cd" color.selected="0x000000" color.normal="#000000"
toolTip="{acName.text}"
/>
<mx:Label visible="false" width="0" height="0" id="acID" />
<mx:Label visible="false" width="0" height="0" id="acGlob"/>
<mx:Label visible="false" width="0" height="0" id="acVisiO"/>
<mx:Label visible="false" width="0" height="0" id="acVisiV"/>
<mx:Label visible="false" width="0" height="0" id="acRoot" />
</mx:HBox>
谢谢大家