2012-01-31 62 views
0

我有一個mx:列表與自定義的itemrenderer。mx:列表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[ 


/* 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> 

如果使用設定數據功能,則不會出現警告。但在這種情況下,我不知道如何訪問doublelickclik上的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; 

}

感謝訪問幫助

回答

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; 
} 
+0

我試試這個答案,這個錯誤出現的ReferenceError:錯誤#1069:房產2 mx.collections.ArrayList沒有發現,也沒有默認值。 – Flex60460 2012-01-31 22:39:43

+0

只是編輯答案,應該工作 – Antonos 2012-02-01 11:23:39

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> 

謝謝大家