Skip to main content
Participant
April 8, 2009
Question

How to access/disable a list item

  • April 8, 2009
  • 1 reply
  • 1221 views

I'm looking for a way to disable a specific item within a List component. I had thought there would be something along the lines of myList.listItems[3].enabled = false like you find in many other GUI type languages, but I can find no documentation of this in Flash AS3.

What confuses me is that there is Disabled_skin and Selected_disabled in the Cell Renderer skins, so obviously it's something that has been catered for - unless I've misunderstood the use.

Does anyone know how to do this?

This topic has been closed for replies.

1 reply

RossRitchey
Inspiring
April 8, 2009

You are looking for:

myList.dataProvider.getItemAt(3).enabled = false;

I believe.

silentCAuthor
Participant
April 8, 2009

Thanks for the reply, Ross.

I gave that a try and, whilst it didn't give me any errors, it appeared to have no effect. I tried an index which I knew was outside the range and it returned an error, so the code is obviously doing the right thing but setting 'enabled' to false doesn't seem to disable the item in the list. It doesn't gray it out and it can still be selected. Maybe it's something to do with the way I'm setting up the list. I created the list by dropping the component on the stage. Here is the code I'm testing with:

---

for(var i=1;i<21;i++)
    myList.addItem({label:"Question " + String(i),data:i});

myList.dataProvider.getItemAt(3).enabled = false;

---

I also tried myList.getItemAt(3).enabled = false; which, while it gave no error, also appeared to do nothing.

I traced the enabled property before and after the call. Before the call it returns 'undefined' after it returns 'false'. I also traced the label to make sure it was actually selecting the item, which it appears to be. So my conclusion is that Flash is ignoring the enabled property for whatever reason.

I guess I also need to read up on dataProvider. I've successfully avoided it up to this point.

RossRitchey
Inspiring
April 9, 2009

Just did some quick research, and it looks like the List uses "selectable" not "enabled"

so:

myList.dataProvider.getItemAt(3).selectable = false;