Thursday, 26 February 2009

uid property on ActionScript object breaks mx:List

I don't know if this is expected behaviour, but this evening I noticed, much to my annoyance, that having a uid property on an Object causes mx:List to stop handling rollovers and selections properly. Take the following extremely simple example (compared to the code I was actually working on):

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

<mx:ArrayCollection id="sampleData">
<mx:Object uid="" label="Sample 1" />
<mx:Object uid="" label="Sample 2" />
<mx:Object label="Sample 3" />
<mx:Object uid="" label="Sample 4" />
<mx:Object uid="" label="Sample 5" />
</mx:ArrayCollection>

<mx:List dataProvider="{sampleData}" />

</mx:Application>

Only the last and 3rd item in the list receive roll over events, and while selection does actually appear to work, the highlighting of the selected item doesn't.

You can see it working (or not) here.

5 comments:

raducocieru said...

If you remove the UID property on the Objects Flex will generate a valid/unique UID. This is expected behavior.

Chris Brind said...

Fair enough, do you have a link to the documentation in which it says it is expected behaviour?

It is annoying if your model objects have a UID property on them.

Matthew said...

mx:List uses the uid property to map objects to renderers, so non-unique uids mess things up quite a bit.

Many Flex classes assume uid uniqueness - which makes sense, right? Even having multiple objects with uid=null is a problem.

Chris Brind said...

I hear what you're saying but objects have a natural uniqueness called an object reference, no need for reliance on artifical uids. Of course, UIDs are useful for relating objects that have been serialised, but within a single VM the object reference should be enough, IMHO.

Matthew said...

Ahhh .. an idealist ;)

This page gives some useful info: http://livedocs.adobe.com/flex/3/html/help.html?content=about_dataproviders_8.html

Flex can use internal uids (something like an object reference) for objects without specific uids. But 'artificial' uids are useful in a few situations, especially handling equality with objects and wrappers/proxies.

My advice is - if you need a uid property, make sure it's set to something unique.