2009/08/17

ActionScript: TileList, deleting, scrolling backwards

I have a Flex app which shows users a TiledList of chemical structure depictions. Since it can be a large list, it's lazy-loaded from the server as the user scrolls through the list.

Users can delete items from the list, with undo. In order to do this with reasonable performance, once the app has received confirmation from the server that an item has been deleted, it clears out the single deleted item from its local lazy-list.

To undo the deletion locally, the Flex app fills the correct lazy-list entry with an ItemPendingError; that error gets thrown as soon as the TileList tries to retrieve the item.

All of this works okay when the row containing the undeleted item is already visible. On the other hand, if the user has scrolled away from the row where the undeleted item will reappear, then when (s)he scrolls back the TileList simply empties out that item and all of the successive items in the row. Ugly!

ugly_repaint.png


Workaround

When the item is undeleted, immediately try to retrieve it via getItemAt(itemIndex). Catch the resulting ItemPendingError and register an ItemResponder. When the ItemResponder's result or fault method is called, tell the TileList to invalidateList(). If the undeleted item actually contains a value, the TileList will repaint correctly -- no more unsightly gaps.


import mx.collections.errors.ItemPendingError;
import mx.collections.ItemResponder;
[...]
try {
structures.getItemAt(offset);
} catch (e:ItemPendingError) {
e.addResponder(
new ItemResponder(
function(result:Object, token:Object = null):void {
tilelist.invalidateList();
},
function(error:Object, token:Object = null):void {
tilelist.invalidateList();
}));
}

2009/08/10

I like Mike -- General Michael Collins, That Is

This year's John Glenn Lecture Series featured Sen. Glenn, Chris Kraft and the three Apollo 11 astronauts. Michael Collins was as smart, funny and humble as in "When We Left Earth." His talk starts roughly 55 minutes in.

Apologizing for the lecture-unfriendly layout of the IMAX theater, which he helped approve:

"I'm down here in the bottom of a black hole about to be sucked in by gravity..."


After putting up this picture, which he took as the LEM began its descent to the lunar surface:
michael_collins_background_img.png
"I like that photo, it's my favorite one. You see in the little thing there are 3 billion people, and then in the big thing there are two people..."


About the glistening blue earth in the background:
"Serene it is not. Fragile it is. The world population when we flew to the moon was 3 billion people. Today it's over six and headed for eight, so the experts say. In my view this growth is not wise, healthy or sustainable[...]
"Our economic models are all predicated on growth. They require it. Grow or die, or maybe both: the dead zone created by the runoff from the Mississippi into the Gulf of Mexico is now larger than the State of New Jersey, and still growing...
"We need a new economic paradigm that somehow can produce prosperity without this kind of growth."



The video: http://www.youtube.com/watch?v=w9fCPhspOCQ