While working with the
TileList component I ran into a very odd issue. Images would move around while scrolling up and down. Also when I updated the dataProvider the TileList didn't display the new information.
Here is an example so you can see what is going on. You can view the source the source by right-clicking and selecting "View Source".
After a lot of research, and a post on
StackOverflow, I figured out what was going on. My broken example relies on a MXML completion method (init, creationComplete, etc..) to set the source of the image in the itemRenderer.
index.mxml
2 | <itemRenderers:ImageTile_bad /> |
ImageTile_bad.mxml
01 | <?xml version= "1.0" encoding= "utf-8" ?> |
08 | private function init() : void { |
10 | this .name = data.toString().split( "/" ).pop().split( "." ).shift(); |
TileList reuses cells inside the component. I'm not sure why, but can't keep track of where things should render and starts switching images around. I tried overridding the
data method and it works, but I wanted to find a solution that doesn't require overriding a private method.
The answer is to use a setter inside the itemRenderer to assign the value to the component. Here is a snip-it of code to show you what I mean.
index.mxml
2 | <itemRenderers:ImageTile img= "{data}" /> |
ImageTile.mxml
08 | public function set img(value: String ) : void { |
14 | this .name = value.toString().split( "/" ).pop().split( "." ).shift(); |
When
TileList redraws the cell it will pass
data into the img setter. This will make sure that the cell receives the correct information when it redraws. Also switching the dataProvider on the TileList works properly now.
Here is a link to the working example that has available source code. Feel free to contact me if you have any questions.