1 Reply Latest reply on Jul 6, 2007 9:58 AM by kcell

    horizontalList + Array

    gongon2
      I've already posted this into Flex General but i've probably mistake forum..

      Hi! (sorry for my poor english..)
      I'd try yo populate an horizontalList width a list of images defined by an array loaded from mySql through an amfPHP simple service.
      Data (images path) are loaded correctly in the movie (in fact, you can see them in the dataGrid) but the horizontalList return a list of empty image fields.

      You can see it here :
      http://www.gongon2.com/flex/pippo/bin/OrizList.html

      This is the source code :

      <?xml version="1.0"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" height="208" width="800" creationComplete="initApplicationPippo()">
      <mx:Script>
      <![CDATA[
      import mx.collections.*;
      import mx.controls.Image;
      import mx.rpc.events.ResultEvent;
      import mx.utils.ArrayUtil;


      [Bindable]
      public var pippo:Array;
      public var gatewayPippo : RemotingConnection;

      public function initApplicationPippo():void{
      gatewayPippo = new RemotingConnection( " http://www.gongon2.com/flashservices/gateway.php" );
      gatewayPippo.call( "sampleOL.getUserPhoto", new Responder(onResult, onFault),"1");
      }

      public function onResult( result : Array ) : void
      {
      pippo = result;
      myList.dataProvider = pippo;
      }


      public function onFault( fault : String ) : void
      {
      trace( fault );
      }

      ]]>
      </mx:Script>

      <mx:HorizontalList id="myList" columnWidth="100" rowHeight="100" columnCount="4" itemRenderer="mx.controls.Image" x="10" y="25" height="120" width="400"/>

      <mx:Image x="418" y="25" width="100" height="100" id="image" source="{myList.selectedItem.photoPath}"/>

      <mx:DataGrid dataProvider="{pippo}" x="578" y="25" id="grid" height="130" width="104">
      <mx:columns>
      <mx:DataGridColumn headerText="photoPath" dataField="photoPath"/>
      </mx:columns>
      </mx:DataGrid>

      <mx:Image x="690" y="25" width="100" height="100" source="{grid.selectedItem.photoPath}"/>
      </mx:Application>

        • 1. Re: horizontalList + Array
          kcell Level 2
          I think your problem is that the itemrender expect as dataprovider an array of string objects where the string are the imagepaths.

          In the mx:image you use source="{myList.selectedItem.photoPath}", so I think that the array is an array of objects.

          You can use a

          A: custom itemrender (as in the example of the HorizontalList in the flexbuilder help)

          <?xml version="1.0" ?>
          <!-- itemRenderers\htlist\myComponents\Thumbnail.mxml -->
          <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml"
          horizontalAlign="center"
          verticalGap="0" borderStyle="none" backgroundColor="white" >

          <mx:Image id="image" width="60" height="60" source="{data..photoPath}"/>
          </mx:VBox>

          B: or you build a new array of strings where you just add the photoPath values and make this array the dataprovider for the HorizontalList .