dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Disabling list item?

  1. #1
    Senior Member
    Join Date
    Apr 2003
    Location
    MA
    Posts
    273

    Disabling list item?

    This is driving me crazy, it seems like it should be simple but I haven't been able to find any documentation on it anywhere. I have a List() that I've created and populated with a DataProvider. I want it so that when you click on a list item that item becomes disabled (in the same way you set list.enabled = false).

    Since I haven't found out how to disable the list, I have something like this which just removes the entry:

    Code:
    list.addEventListener(Event.CHANGE, stuff);
    
    function stuff(event:Event) {
        list.removeItem(event.target.selectedItem);
    }
    I've tried event.target.enabled = false and event.target.selectedItem.enabled = false and neither are working, and I can't find jack diddly anywhere about how to disable individual list items so that you can't click on them.

  2. #2
    Junior Member
    Join Date
    Oct 2002
    Posts
    15
    Yes - I've also been searching around for what seems a rather essential thing - being able to disable a row/item in a list component. Have found an AS2 answer that may or may not work - but, like you, I'm looking for something in AS3.

    Where I've got to:

    I've created a new class that extends the CellRenderer class (and so implements ICellRenderer).

    I've overridden the set listData method. In the new method, I check for the presence or lack of a data element (enabled, say) and can then set the style of that row accordingly.

    What I can't work out how to do is stop that row from responding to rollover and mouseUp/Down events. Presumably I need to removeEventHandler from that row - but what is the event handler called for the CellRenderer class?

    Anyone got any thoughts on how to achieve this - either by completing this method above or via some other route?

    What would obviously help is some sort of more complete documentation on dealing with the components - but haven't seen anything beyond the adobe livedocs which are very far from complete as far as I can tell.

    Thanks,

    Alex

  3. #3
    Junior Member
    Join Date
    Oct 2002
    Posts
    15
    After some more experimenting - here's the solution, I think. Might help some googlers ...

    First create a new cellRenderer file - I've called the cell renderer mc_sw_cell, so it goes in the file mc_sw_cell.as.

    Then enter the following code. This disables the row where it has a property of v_enabled == "false". It also grays out the row text - substitute your own text format if you want something different.

    package {

    import fl.controls.listClasses.CellRenderer;
    import flash.text.TextFormat;

    class mc_sw_cell extends CellRenderer {

    private var tf:TextFormat = new TextFormat();

    public function mc_sw_cell() {

    }

    override public function set data(newData:Object):void {
    _data = newData;

    tf.font = "ITC Officina Sans Book";
    tf.size = 16;
    tf.bold = false;
    tf.color = 0x777777;
    tf.leading = -4;
    tf.align = "center";

    var originalStyles:Object = CellRenderer.getStyleDefinition();

    setStyle("upSkin", originalStyles.upSkin);
    setStyle("downSkin",originalStyles.downSkin);
    setStyle("overSkin",originalStyles.overSkin);
    setStyle("selectedUpSkin",originalStyles.selectedU pSkin);
    setStyle("selectedDownSkin",originalStyles.selecte dDownSkin);
    setStyle("selectedOverSkin",originalStyles.selecte dOverSkin);

    if (_data.v_enabled == "false") {
    setStyle("textFormat", tf);
    mouseEnabled = false;
    }

    }

    }

    }

    Finally, set your list view's (here called aList) cellRenderer to your new one:

    aList.setStyle('cellRenderer', mc_sw_cell);

    And, for instance, add disabled rows with:

    aList.addItem({label:v_label, data:v_id, v_enabled: "false"});

  4. #4
    Junior Member
    Join Date
    Nov 2009
    Posts
    10
    does anyone know how to stop the whole list from going grey when
    PHP Code:
    list.enabled false
    ???????

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center