This content has been marked as final. Show 5 replies
The dataProviders in Flex list controls use Collections like ArrayCollection. The Array class is part of the Flash Player intrinsic classes. Flex list controls listen for Flex events dispatched by the Collection classes when they are changed. The list controls also assume the dataProviders implements a few ActionScript interfaces.
So that's why the Array didn't work. Use ArrayCollection instead; use addItem() instead of push().
Awesome peterent, thanks!
However, that does render the 3 items with their label in the TileList component but it doesn’t render the icon. The browser doesn’t render the missing file icon that it does when it can’t find a file even if I intentionally change the embedded source value. So it seems to me Flex is not even trying to embed the icon.
TileList, as with the other list-based controls in Flex, don't know you want to see something special when you give them a dataProvider. How are they to tell what you want to see? Their default behavior is to show text, usually the field within your data called "label".
If you want to see something else, you'll need to create an "itemRenderer" - a component which will be used as a template for all of the items in the list. You can find lots of examples of itemRenderers, even ones with images, by searching the Flex documentation for itemRenderer.
I was under the assumption that an MX tag name (e.g. mx:Array) correlates to an ActionScript class. This assumption seems to be invalid as you pointed out previously. Perhaps a poster size cheat-sheet of the API would clear up a lot of confusion on inheritance of classes for me.
Back to your last post, you mentioned that list-based controls in Flex needs an “itemRenderer” to render something other then text, such as an image. However if I uncomment the MX code in my original post, the TileList renders the embedded icon. So that begs the question, is the MX code implicitly importing/inheriting an “itemRenderer”?
Yes, all of the list-based components use a default item renderer. Starting with the code for these is often a good way to create your own item renderer. I have used ListItemRenderer.as and looked at DataGridItemRenderer.as. The are pretty easy to understand, and are well commented.
However, item renderers are a bit complex, because of their tight integration with the framework.
Consider using mx:Repeater inside of a mx:Tile container. You still should create a custom component, and repeat that, but the component does not need to integrate with the List, so can be simpler to code. Pass a ref to the entire dataProvider item, via currentItem, into the component. You can then code it normally, without worring about event timing and scoping and getRepeaterItem and such.