简体   繁体   中英

How do I deselect all checkboxes in Flex 4

I am trying to deselect all checkboxes on a button click. I've tried creating a binded boolean variable like this:

[Bindable]
public var allselected:Boolean;

and then on my checkboxes:

<s:CheckBox selected="{allselected}" label="PT Identified" />
<s:CheckBox selected="{allselected}" label="Chart Reviewed"/>
<s:CheckBox selected="{allselected}" label="H&amp;P"/>
<s:CheckBox selected="{allselected}" label="Permit Signed"/>

On a separate button click I set the boolean variable to false and nothing happens after I've already checked a checkbox. If I set the boolean variable to true, all the checkboxes get checked. So, if I wanted to select all, then it works. However, I want to deselect all selected checkboxes.

The checkboxes only reside withing a tilegroup and are not inside a datagrid or datagroup. I would think that there is a simple way to do this but I've yet to figure it out. Any suggestions would be greatly appreciated.

I had a dirty solution. Give ids to checkboxes and use the following function for Button click:

protected function untick_clickHandler(event:MouseEvent):void{
            cb1.selected=false;
            cb2.selected=false;
            cb3.selected=false;
        }
public function findChild(numChilds:int, parent:Object):void
        {
            for (var i:int = 0; i < numChilds; i++)
            {
                var obj:Object = parent.getChildAt(i);
                if(obj.hasOwnProperty('selected'))
                {
                    if(obj.selected == true)
                    {
                        obj.selected = false;
                    }
                }
                if (obj is DisplayObjectContainer)
                {
                    // search for children
                    var children:int = obj.numChildren;
                    findChild(children, obj);
                }
            }
        }

Usage:

var elems:int = checklistVgroup.numChildren;  // Get the number of elements

findChild(elems, checklistVgroup);            // Use our function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM