views:

23

answers:

0

Hello,

I'm new here and to Flex. Hope someone can help me out. I've searched around this site and google in general for a solution to my problem but no joy so far.

I have a custom version of a combobox (named MultiplePriority) which extends ComboBox. It's basically a combo box but with checkboxes for its elements as opposed to just a list of things. This custom combo box uses a custom item renderer (called ComboCheckItemRenderer).

There are a few things going on in the code that I don't quite get (I'm new to Flex and am trying to get a handle on someone else's code... though I do have experience in C++ and Java). For example:

public function MultiplePriority() {
        super();
        addEventListener("comboChecked", onComboChecked);
        var renderer:ClassFactory = new ClassFactory(ComboCheckItemRenderer);
        itemRenderer=renderer;
        var myDropDownFactory:ClassFactory = new ClassFactory(ComboCheckDropDownFactory);
        super.dropdownFactory=myDropDownFactory;
        selectedItems=new ArrayCollection();
    }

I get that a factory is being created and that this is being set as the item renderer but am not really sure why.

Anyway, my problem:

I want to be able to influence the values of flex UI controls by passing values via URL parameters. This has worked fine so far with combo boxes, check boxes and clicking buttons. However, for this custom combo box, it's proving more difficult. I want to be able to set the value of specific check boxes in this custom combo box as I wish. I'm not even sure if this is possible but thought I'd ask here since I seem to have hit a bit of a brick wall with it.

The rest of the code in case it helps.

import flash.events.Event;

import mx.collections.ArrayCollection;
import mx.controls.ComboBox;
import mx.core.ClassFactory;

[Event(name="addItem", type="flash.events.Event")]

public class MultiplePriority extends ComboBox {
    private var _selectedItems:ArrayCollection;

    [Bindable("change")]
    [Bindable("valueCommit")]
    [Bindable("collectionChange")]

    public function set selectedItems(value:ArrayCollection):void {
        _selectedItems=value;
    }

    public function get selectedItems():ArrayCollection {
        return _selectedItems;
    }

    public function MultiplePriority() {
        super();
        addEventListener("comboChecked", onComboChecked);
        var render:ClassFactory = new ClassFactory(ComboCheckItemRenderer);
        itemRenderer=render;
        var myDropDownFactory:ClassFactory = new ClassFactory(ComboCheckDropDownFactory);
        super.dropdownFactory=myDropDownFactory;
        selectedItems=new ArrayCollection();
    }

    private function onComboChecked(event:ComboCheckEvent):void {
        var obj:Object=event.obj;
        var index:int=selectedItems.getItemIndex(obj);
        if (index==-1) {
            selectedItems.addItem(obj);
        } else {
            selectedItems.removeItemAt(index);
        }

        if (selectedItems.length>1) {
           // text='multiple'
           //modified by samuel

           var items:ArrayCollection = selectedItems;
var selItems:String = "";

           for (var item:String in items) 
{  
 if (items[item].label != "ALL" ) {
  selItems = selItems + items[item].label + ",";
 }
} 

if (selItems.length > 0){
 selItems = selItems.substr(0,selItems.length - 1);
}


           text = selItems;
        }
        if (selectedItems.length==1) {
            text=selectedItems.getItemAt(0)[labelField];
        }
        if (selectedItems.length<1) {
         //modified by samuel
            text="ALL";
        }

        dispatchEvent(new Event("valueCommit"));
        dispatchEvent(new Event("addItem"));
    }

override public function set dataProvider(value:Object):void {
super.dataProvider = value;
for each (var obj:Object in dataProvider) {
   if (obj['assigned']!= null && obj['assigned']==true) {
    selectedItems.addItem(obj);
   }
}

dispatchEvent(new Event("valueCommit"));
dispatchEvent(new Event("addItem"));
}        

}

import flash.events.Event;
import flash.events.MouseEvent;

import mx.controls.List;
import mx.controls.listClasses.*;

[Event(name="comboChecked", type="com.seagate.flex.combocheck.ComboCheckEvent")]

public class ComboCheckDropDownFactory extends List {

    private var index:int=0;
    public function ComboCheckDropDownFactory(): void {
        addEventListener("comboChecked", onComboChecked);
    }

    override protected function mouseEventToItemRenderer(event:MouseEvent):IListItemRenderer {
        var row:IListItemRenderer = super.mouseEventToItemRenderer(event);
        if (row!=null) {
            index=itemRendererToIndex(row);
        }
        return null;
    }
    private function onComboChecked (event:Event):void {
        var myComboCheckEvent:ComboCheckEvent=new ComboCheckEvent(ComboCheckEvent.COMBO_CHECKED);
        myComboCheckEvent.obj=ComboCheckEvent(event).obj;
        owner.dispatchEvent(myComboCheckEvent);
    }
}