[Fixed] ListBase TypeError #1010

Today I spent hours tracking down a bug related to inserting and/or deleting data from a Tree control. In certain circumstances, an update to the underlying dataProvider would cause the following to be reported:

TypeError: Error #1010: A term is undefined and has no properties.
at mx.controls.listClasses::ListBase/makeRowsAndColumnsWithExtraRows()

After a bit of Googling, I found that I am not alone. Other folks have the same issue with Tree. Even more common, it looks like people are getting the same error when manipulating data in an AdvancedDataGrid, in which case it is reported as:

TypeError: Error #1010: A term is undefined and has no properties. at mx.controls.listClasses::AdvancedListBase/makeRowsAndColumnsWithExtraRows()

After drilling down into the Flex Framework source and exploring the makeRowsAndColumnsWithExtraRows function, I added some watch expressions in the Flash Builder Debug pane. (The debug features are really, really useful for this kind of thing.) The culprit? The value for verticalScrollPosition was being reported as -1, causing a line of code to look for an array element at index -1. This array element was in turn undefined, so the error message suddenly makes perfect sense.

The real puzzler here is that verticalScrollPosition could ever be less than zero. This is the logical equivalent of scrolling to the top of the list, then scrolling up one more spot, which is of course impossible. In any case, I have decided to assume that -1 is invalid at all times, and that -1 really means 0. I hope that is a safe assumption!

So, the solution is simple. In my case I had already subclassed the Tree control. If you're using the stock control from the framework, you'll need to subclass it and simply add the following:

override public function get verticalScrollPosition():Number
{
return Math.max(0, super.verticalScrollPosition);
}

All it does is intercept any request for verticalScrollPosition and guarantee that it is greater than or equal to zero. In brief testing, the error has disappeared and I have seen no side effects.

Like anything else on this blog, use this fix at your own risk, since I can't guarantee it won't have any negative impact.

Happy coding!

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
rb's Gravatar hi & thanks for a nice workaround!

Is it already reported in the bug system? I couldn't find any issue related to this error.

Regards,
Robert
# Posted By rb | 5/30/11 8:43 AM
Josh's Gravatar Robert,

I am not aware of this issue existing in the Adobe bug system. The project I was working on is rather complex, so I can't really write out a simple list of steps to reproduce the issue, and therefore I didn't bother reporting it.

Thanks for reading!

-Josh
# Posted By Josh | 6/1/11 1:29 PM
Marty's Gravatar Thanks for posting this! I was pulling my hair out over it. I debugged and found the same thing you did (that verticalScrollPosition was reporting -1) but it didn't occur to me how to fix it. Nice work!
# Posted By Marty | 11/4/11 5:36 PM
Pete's Gravatar I'm going to be nice to people all day now, because you solved this thing for me. You deserve a Nobel Peace Prize. Great work!
# Posted By Pete | 12/22/11 10:50 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner