2012-03-01 66 views
0

我有如下列表:刷新每個項目的itemRenderer List組件的Flex

<s:List id="list2" width="100%" height="100%" dataProvider="{ recordingsShown }" 
       itemRenderer="components.VideoItemRenderer2" 
       selectedIndex="0" visible="false"> 

      <s:layout> 

       <s:TileLayout id="tilelayout" 
           useVirtualLayout="true" 
           orientation="columns" 
           columnAlign="justifyUsingWidth" rowAlign="justifyUsingHeight" 
           requestedColumnCount="3" 
           requestedRowCount="2" 
           paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5" 
           verticalGap="10" horizontalGap="10" /> 

      </s:layout> 

</s:List> 

,顯示在瓷磚的名稱,日期和包含在的每部影片的預覽圖像arraycollection recordingsShown作爲dataprovider給出。 問題是,當添加一個新的視頻,我保存的文件夾中預覽PIC和節點描述它在XML和我提出一個新的項目在ArrayCollection中與

recordingsShown.addItemAt(newRecording,0); 

它在舞臺上添加,但沒有顯示最後添加的視頻的預覽圖像! 我如何重新繪製整個列表才能顯示它?

這裏是我的itemRenderer:

<?xml version="1.0" encoding="utf-8"?> 
<s:ItemRenderer 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="400" height="300" autoDrawBackground="true"> 

<fx:Metadata> 
    [Event(name="playClicked", type="flash.events.Event")] 
</fx:Metadata> 

<fx:Script> 
    <![CDATA[ 
     import flash.filters.GlowFilter; 

     import mx.controls.Alert; 
     import mx.events.FlexEvent; 
     import mx.formatters.DateFormatter; 




     protected function img_rollOverHandler(evt:MouseEvent):void { 
      Image(evt.currentTarget).filters = [new GlowFilter(0xf7941d)]; 
      Image(evt.currentTarget).alpha = 0.9; 
     } 

     protected function img1_rollOutHandler(evt:MouseEvent):void { 
      Image(evt.currentTarget).filters = []; 
      Image(evt.currentTarget).alpha = 1; 
     } 

     protected function playClickHandler(event:MouseEvent):void 
     { 

      dispatchEvent(new Event("playClicked",true,true)); 

     } 

    ]]> 
</fx:Script> 

<fx:Declarations> 
    <s:DateTimeFormatter id="dateTimeFormatter" 
         dateTimePattern="DD.MM.YYYY HH.NN.SS"/> 
</fx:Declarations> 

    <s:states> 
     <s:State name="normal" /> 
     <s:State name="hovered" /> 
     <s:State name="selected" /> 
    </s:states> 

    <s:Rect width="100%" height="100%" radiusX="5" radiusY="5"> 
     <s:filters> 
      <s:DropShadowFilter alpha="0.32" alpha.hovered="0.5" blurX="5" blurY="5" distance="2" /> 
     </s:filters> 
     <s:fill> 
      <s:LinearGradient rotation="90"> 
       <s:GradientEntry color="0x323232" color.selected="black"/> 
       <s:GradientEntry color="#7f7f7f" color.selected="0x333333"/>     
      </s:LinearGradient> 
     </s:fill> 
     <s:stroke> 
      <s:SolidColorStroke color="#ffffff" color.hovered="#f7941d" color.selected="#ed7f09" caps="none" weight="2" joints="miter" miterLimit="4"/> 
     </s:stroke> 
    </s:Rect> 

    <s:Label left="10" top="10" 
      fontStyle="italic" 
      fontWeight="bold" 
      color="#f7941d" 
      text="{dateTimeFormatter.format(data.date)}"/> 

    <s:Label left="10" top="25" 
      fontSize="16" 
      fontWeight="bold" 
      color="#ffffff" 
      text="{data.name}"/>  
    <s:Image id="previewImg" left="10" right="10" bottom="10" top="55" scaleMode="stretch" smooth="true" 
      source="http://localhost:5080/thumbs/{data.thumb}" /> 
      <!-- source="assets/img.jpg"/> -->    

    <s:Image source="assets/play.png" 
      rollOver="img_rollOverHandler(event);" 
      rollOut="img1_rollOutHandler(event);" 
      x="136" y="102" 
      click="playClickHandler(event)" 
      complete="this.invalidateSize()"/> 
</s:ItemRenderer> 
+0

確保VideoItemRenderer2的設置數據功能正確更新,這可能是回收項目渲染器沒有正確更新的問題。 – 2012-03-01 17:49:48

+0

我該如何檢查?如果你給我任何例子或指示,我將不勝感激。 – sstauross 2012-03-01 17:57:30

+0

確保圖像和其他顯示內容在public function set data(value:Object)中設置:void'在VideoItemRenderer2中。 – 2012-03-01 17:59:33

回答

0

我發現,似乎有使用數據綁定問題,星火圖像。嘗試將此添加到根標記:

dataChange="yourImage.validateNow(); 

如果這樣不起作用,請在dataChange中設置整個路徑。

+0

我把這個,但沒有什麼......你是什麼意思「在dataChange中設置整個路徑」?對不起,但我是所有這些東西的新手..非常感謝您的幫助! – sstauross 2012-03-02 11:05:56

+0

我在想如何才能將加載gif放置在未準備好顯示的圖像的位置?任何幫助?這會解決問題嗎? – sstauross 2012-03-02 11:52:29

+0

而不是將路徑放在previewImage標記中的綁定表達式中,請執行dataChange =「previewImage.source = http:// localhost:5080/thumbs/{data.thumb}」。問題在於數據綁定無論出於何種原因都不適用於火花圖像,因此您需要顯式重置Image標籤外部的源。 – 2012-03-02 13:30:21