PDA

View Full Version : Problems with dataProvider


ziofu
02-06-2007, 02:46 PM
I have some problems providing data to a list.

Take a look at this code:


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="initApp()">

<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;

private var loader:Loader;

private function initApp():void {

loader = new Loader();
var request:URLRequest = new URLRequest("sprites/bricks.gif");
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, onLoadComplete);
loader.load(request);

}

private function onLoadComplete(event:Event):void {
var collection:ArrayCollection = new ArrayCollection();

var item1:Object = new Object();
item1.label = "Item 1";
item1.icon = loader.content;
collection.addItem(item1);

var item2:Object = new Object();
item2.label = "Item 2";
item2.icon = loader.content;
collection.addItem(item2);

hList.dataProvider = collection;
hList.labelField = "label";
hList.iconField = "icon";

// hList.addChild(item2.icon) // works
}

]]>
</mx:Script>

<mx:HorizontalList id="hList" x="10" y="10"></mx:HorizontalList>

</mx:Application>



The problem is that the HorizontalList only shows labels and not images.
I've managed to make it work with embedded images (following the examples on docs) but how to use dynamically loaded images?

Thanks for helping.