简体   繁体   中英

refresh the itemrenderer of each item in the List component Flex

I have the list shown below:

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

which displays in tiles a name, a date and a preview image for each one of the videos contained in the arraycollection recordingsShown given as dataprovider. The problem is when a new video is added,i save the preview pic in a folder and a node describing it in an xml and i put a new item in the arraycollection with

recordingsShown.addItemAt(newRecording,0);

it is added on stage but the preview image of the last added video is not shown! How can i redraw the whole list in order to show it?

Here is my 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>

I have found that there seems to be a problem with data binding and the Spark Image. Try adding this to the root tag:

 dataChange="yourImage.validateNow();

If that doesn't work, set the whole path in dataChange.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM