BIT-101 [2003-2017]

Minimal List


I’m on a roll!

[kml_flashembed publishmethod=“static” fversion=“10.0.0″ movie=“http://www.bit-101.com/blog/wp-content/uploads/2010/03/List.swf” width=“120″ height=“220″ targetclass=“flashmovie”]

Get Adobe Flash player

[/kml_flashembed]

Now that we have a scroll bar, making a List was not all that hard. Here you can see a generic list with 1000 items. The default item color, rollover color and selected color are all customizable, as is the list item height. I improved a bunch of stuff about the scroll bar and a lot of the time this took was going back and forth between the text area and list and making sure the scroll bar worked perfectly in both of them.

You can pass in an array of items in the constructor. Or you can add items manually through addItem or addItemAt. Items can be strings or any object. If the item is an object, it will look for a label property on the object and use that as the item label. You also have removeItem, removeItemAt, and removeAll as well as selectedIndex and selectedItem. I just realized that there is a bug in the downloadable SWC/zipped source versions that will cause an error if you do not pass an array in the constructor. Workaround is to just pass an empty array. This is fixed in the SVN repository.

Eventually, I want to add a listItemClass that will allow you to set a custom class for your list items. Next build for sure. Then you can extend the existing ListItem class and make your own item renderers.

Note that this List does NOT use any smart item creation and swap scrolling. Each item you add is created and put in a container that is scrolled. Even so, at 1000 items, it seems to perform perfectly fine. If you get up into the multiple thousands though, it’s going to start to break down and perform like crap. Also, every time the list is redrawn, all items are removed and recreated. So yes, there’s lots of room for optimization, but for the purposes of “minimal” components, this works fairly well. If you need lists with thousands of items that are updating redrawing all the time with complex item renderers, you have the wrong component set. (I LOVE having that crutch to fall back on!)

Anyway, hope this is useful. I think a Combo Box / Dropdown is on the horizon for the next week or so.

Also, I updated the version numbering. I started out at 0.90 or something and was going 0.91, 0.92, 0.93, etc. then up to 0.100, 0.101, 0.102. But realized this was all wrong. So I’m going with a major.minor.revision system. Thus we have 0.9.0 for the current build. Next will be 0.9.1. Once I add a combo box I’m going to address any remaining bugs, clean up the code even more, solicit any more bugs and enhancements, and when all is nice and stable, call it 1.0.0!

« Previous Post
Next Post »