PDA

View Full Version : How to update the ItemRenderer at runtime??


Pratap
04-18-2008, 06:57 AM
Hi....
am facing a hectic problem with ITemRenderes..

My requirement is like i need to insert a Label and Image in each item of Horizontal List.
For this i created a ArrayCollection with Lable and ImagePath. And assigning array as a Dataprovider to HorizontalList. and am attaching itemrenderer to it (which hold the lable and image).

code:

var data:ArrayCollection=new ArrayCollection({label:'A', path:'a.jpg'}, {label:'B', path:'b.jpg'}{label:'C', path:'c.jpg'});
var hList:HorizontalList=new HorizontalList();
hList.dataProvider=data;
hList.itemRenderer=new ClassFactory(rendererObj);

rendererObj holds the Lable Component and Image Componnet..


Now the porblem is am trying to change the horizontal list at runtime. Like i want to change the lable of selected item in Horizontal list. Am able to update the arraycollection values. But its not getting effected in ItemRenderer.

How to update the itemerenderer at runtime...?


Thanks in Advance...
Pratap

mattb
04-18-2008, 02:39 PM
The problem is that the objects you're creating inside your ArrayList won't have bindable properties... so the itemRenderer components (Label etc) won't be able to watch for changes.

What you should do is create a separate class to hold the label and path data and make the properties bindable, eg:


class MyData {
[Bindable]
public var label:String;

[Bindable]
public var path:String;

public mydata(in_Label:String, in_Path:String) {
label = in_Label;
path = in_Path;
}
}


Note you should really make the properties private and create bindable setter/getter functions, but you get the idea.

Then your ArrayCollection code would look like:


var data:ArrayCollection = new ArrayCollection(new MyData("A", "a,jpg"), new MyData("B, "b.jpg"));