views:

447

answers:

2

I have created a module with 3 states as an itemrenderer. The states are called Movies, Songs and TvShows. The base state is empty. The itemRenderer consists of Hbox, Vboxes and labels.

And I have created a List component.

What I want to do is to populate data in my List component and make it visible using my ItemRenderer. Depending on the data that is pulled out from the database I want to show the itemRenderer's correct state. Hence if the record pulled out from the database is a song, I want to display the Song state, if it is a movie, I want to show the Movie state and so on.

So depending on the data that's pulled out, I would like to change the current state of itemrenderer. How would i do that? Can anybody show me an example how i would make this code?

Thanks

+1  A: 

override the set data method of your CustomItemRenderer and assign the appropriate state based on the data.

override public function set data(value:Object):void
{
  super.data = value;
  if(data.type == "song")
    this.currentState = SONG_STATE;
  else if(data.type == "movie")
    this.currentState = MOVIE_STATE;
  else if //and so on...
}
Amarghosh
A: 

thanks it worked well. The Only thing i notice was that:

this.currentState = MOVIE_STATE;

should be

this.currentState = "MOVIE_STATE";

thanks

DJ

DJ
If you are new to SO, you might wanna read this http://meta.stackoverflow.com/questions/5234/accepting-answers-what-is-it-all-about
Amarghosh