Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 更改处理程序在Flex中未第一次触发_Actionscript 3_Apache Flex_Flash Builder_Flex3_Flex4.5 - Fatal编程技术网

Actionscript 3 更改处理程序在Flex中未第一次触发

Actionscript 3 更改处理程序在Flex中未第一次触发,actionscript-3,apache-flex,flash-builder,flex3,flex4.5,Actionscript 3,Apache Flex,Flash Builder,Flex3,Flex4.5,我使用多重检查下拉列表,它不会触发第一个更改事件。后续事件正确触发。当我第一次选择全选或任何其他选项时,它也不会触发事件 use namespace mx_internal; [Style(name="selectAllBorderAlpha", type="Number", inherit="no", theme="spark, mobile", minValue="0.0", maxValue="1.0")] [Style(name="selectAllBorderColor", type

我使用多重检查下拉列表,它不会触发第一个更改事件。后续事件正确触发。当我第一次选择全选或任何其他选项时,它也不会触发事件

use namespace mx_internal;

[Style(name="selectAllBorderAlpha", type="Number", inherit="no", theme="spark, mobile", minValue="0.0", maxValue="1.0")]
[Style(name="selectAllBorderColor", type="uint", format="Color", inherit="no", theme="spark, mobile")]
[Style(name="selectAllBorderVisible", type="Boolean", inherit="no", theme="spark, mobile")]
[Style(name="selectAllBackgroundColor", type="uint", format="Color", inherit="no", theme="spark, mobile")]
[Style(name="selectAllBackgroundAlpha", type="Number", inherit="no", theme="spark, mobile", minValue="0.0", maxValue="1.0")]

[IconFile("DropDownList.png")]

[DiscouragedForProfile("mobileDevice")]
public class CheckBoxDropDownList extends CheckBoxDropDownListBase
{
  public function CheckBoxDropDownList()
  {
    super();
    addEventListener(IndexChangeEvent.CHANGE, indexChangeHandler);
  }

  protected function indexChangeHandler(event:IndexChangeEvent):void
  {
    selectedAll = false;
  }

  [SkinPart(required="false")]
  public var selectAllCheckBox:CheckBox;

  [SkinPart(required="false")]
  public var selectAllHitArea:UIComponent;

  [SkinPart(required="false")]
  public var labelDisplay:IDisplayText;

  private var labelChanged:Boolean = false;
  private var labelDisplayExplicitWidth:Number; 
  private var labelDisplayExplicitHeight:Number; 
  private var sizeSetByTypicalItem:Boolean;

  override public function get baselinePosition():Number
  {
    return getBaselinePositionForPart(labelDisplay as IVisualElement);
  }

  private var _prompt:String = "";

  [Inspectable(category="General", defaultValue="")]

  public function get prompt():String
  {
    return _prompt;
  }

  public function set prompt(value:String):void
  {
    if (_prompt == value)
      return;

    _prompt = value;
    labelChanged = true;
    invalidateProperties();
  }

  [Inspectable(category="Data")]

  override public function set typicalItem(value:Object):void
  {
    super.typicalItem = value;
    invalidateSize();
  }

  override protected function commitProperties():void
  {
    super.commitProperties();           

    if (labelChanged)
    {
      labelChanged = false;
      updateLabelDisplay();
    }

    if (selectedAllChanged)
    {
      selectedAllChanged = false;

      if (selectAllCheckBox)
      {
        selectAllCheckBox.selected = _selectedAll;
        this.dispatchEvent(new Event("selectAllChanged"));
      }
      invalidateList();
    }
  }

  override protected function partAdded(partName:String, instance:Object):void
  {
    super.partAdded(partName, instance);

    if (instance == labelDisplay)
    {
      labelChanged = true;
      invalidateProperties();
    }

    if (instance == selectAllCheckBox)
    {
      selectedAllChanged = true;
      invalidateProperties();
    }

    if (instance == selectAllHitArea)
    {
      selectAllHitArea.addEventListener(MouseEvent.CLICK, selectAllHitArea_clickHandler);
    }
  }

  override protected function partRemoved(partName:String, instance:Object):void
  {
    super.partRemoved(partName, instance);

    if (instance == selectAllHitArea)
    {
      selectAllHitArea.removeEventListener(MouseEvent.CLICK, selectAllHitArea_clickHandler);
    }
  }

  protected function selectAllHitArea_clickHandler(event:MouseEvent):void
  {
    if (selectAllCheckBox)
      selectedAll = !selectAllCheckBox.selected;
  }

  private var _selectedAll:Boolean = false;
  private var selectedAllChanged:Boolean;

  public function get selectedAll():Boolean
  {
    return _selectedAll;
  }

  public function set selectedAll(value:Boolean):void
  {
    if (value == _selectedAll)
      return;

    _selectedAll = value;           
    selectedAllChanged = true;
    labelChanged = true;

    selectedIndices = Vector.<int>([]);
    //setSelectedItem(undefined, false);

    invalidateProperties();
  }

  public function setSelectedIndices(selValues:Array):void
  {
    if (this.dataProvider == null) {
      return;
    }

    var selIndices:Vector.<int> = new Vector.<int>();

    if (selValues == null || selValues.length == 0)
    {
      this.selectedAll = true;
      return;
    }

    for(var i:int=0; i < this.dataProvider.length; i++)
    {
      for(var j:int=0; j < selValues.length; j++)
      {
        var obj:Object = this.dataProvider.getItemAt(i);

        if(selValues[j] == obj.value || selValues[j] == obj.label)
        {
          selIndices.push(i);   
          break;
        }
      }
    }

    if (selIndices.length == 0)
    {
      this.selectedAll = true;
    }
    else
    {
      this.selectedAll = false;
      this.selectedIndices = selIndices; 
    }
  }

  override protected function item_mouseDownHandler(event:MouseEvent):void
  {
    if (selectedAll)
    {
      selectedAll = false;

      var newIndex:int
      if (event.currentTarget is IItemRenderer)
        newIndex = IItemRenderer(event.currentTarget).itemIndex;
      else
        newIndex = dataGroup.getElementIndex(event.currentTarget as IVisualElement);

      var arr:Array = dataProvider.toArray()
      arr.splice(newIndex, 1);
      selectedItems = Vector.<Object>(arr);

      return;
    }
    super.item_mouseDownHandler(event);

    // if all items are selected, then unselect them and check the "Select All" checkbox.
    if (selectedItems.length == dataProvider.length)
    {
      selectedAll = true;
      selectedIndex = -1;
    }
  }

  override protected function dropDownController_closeHandler(event:DropDownEvent):void
  {
    super.dropDownController_closeHandler(event);

    // Automatically selected all items if no items are selected when closing the dropDown.
    if (selectedItems.length == 0 && !selectedAll)
      selectedAll = true;
  }

  override protected function measure():void
  {
    var labelComp:TextBase = labelDisplay as TextBase;

    // If typicalItem is set, then use it for measurement
    if (labelComp && typicalItem != null)
    {   
      // Save the labelDisplay's dimensions in case we clear out typicalItem
      if (!sizeSetByTypicalItem)
      {
        labelDisplayExplicitWidth = labelComp.explicitWidth;
        labelDisplayExplicitHeight = labelComp.explicitHeight;
        sizeSetByTypicalItem = true;
      }

      labelComp.explicitWidth = NaN;
      labelComp.explicitHeight = NaN;

      // Swap in the typicalItem into the labelDisplay
      updateLabelDisplay(typicalItem);
      UIComponentGlobals.layoutManager.validateClient(skin, true);

      // Force the labelDisplay to be sized to the measured size
      labelComp.width = labelComp.measuredWidth;
      labelComp.height = labelComp.measuredHeight;

      // Set the labelDisplay back to selectedItem
      updateLabelDisplay();
    }
    else if (labelComp && sizeSetByTypicalItem && typicalItem == null)
    {
      // Restore the labelDisplay to its original size
      labelComp.width = labelDisplayExplicitWidth;
      labelComp.height = labelDisplayExplicitHeight;
      sizeSetByTypicalItem = false;
    }
    super.measure();
  }

  override mx_internal function updateLabelDisplay(displayItem:* = undefined):void
  {
    if (labelDisplay)
    {
      if (displayItem == undefined)
      {
        if (selectedItems != null && selectedItems.length > 1)
          displayItem = VectorUtils.vectorToArray(selectedItems, Object);
        else
          displayItem = selectedItem;
      }

      if (displayItem != null && displayItem != undefined)
        if (displayItem is Array)
        {
          this.toolTip = selectedItemsToLabel(displayItem, labelField, labelFunction);
          labelDisplay.text = (displayItem as Array).length + " selected";
        }
        else
        {
          this.toolTip = null;                      
          labelDisplay.text = selectedItemsToLabel(displayItem, labelField, labelFunction);
        }
      else if (selectedAll)
        labelDisplay.text = "All";
      else
        labelDisplay.text = prompt;
    }   
  }

  private function invalidateList():void
  {
    if (dataGroup == null)
      return;

    for each (var itemIndex:int in dataGroup.getItemIndicesInView())
    {
      var renderer:UIComponent = dataGroup.getElementAt(itemIndex) as UIComponent;
      if (renderer)
        renderer.invalidateDisplayList();
    }
  }

  private function selectedItemsToLabel(item:Object, labelField:String=null, labelFunction:Function=null):String
  {
    if (labelFunction != null)
      return labelFunction(item);

    var collection:ICollectionView = null;
    if (item is Array)
    {
      collection = new ArrayCollection(item as Array);
    }
    else if (item is ICollectionView)
    {
      collection = ICollectionView(item);
    }
    else if (item is IList)
    {
      collection = new ListCollectionView(IList(item));
    }

    if (collection != null)
    {
      var itemLabels:Array = [];
      for each (var obj:Object in collection)
      {
        itemLabels.push(obj[labelField]);
      }
      return itemLabels.join(", ");
    }
    return LabelUtil.itemToLabel(item, labelField, labelFunction);
  }

  public function get selectedValues():Array
  {
    var arr:Array = [];

    if(selectedItems != null && selectedItems.length > 0)
    {
      for each (var obj:Object in selectedItems)
        arr.push(obj.value);
    }
    return arr;
  }

  public function get selectedLabels():Array
  {
    var arr:Array = [];

    if(selectedItems != null && selectedItems.length > 0)
    {
      for each (var obj:Object in selectedItems)
      arr.push(obj.label);
    }
    return arr;
  }
}
使用名称空间mx_internal;
[Style(name=“selectAllBorderAlpha”,type=“Number”,inherit=“no”,theme=“spark,mobile”,minValue=“0.0”,maxValue=“1.0”)]
[Style(name=“selectAllBorderColor”,type=“uint”,format=“Color”,inherit=“no”,theme=“spark,mobile”)]
[Style(name=“selectAllBorderVisible”,type=“Boolean”,inherit=“no”,theme=“spark,mobile”)]
[Style(name=“selectAllBackgroundColor”,type=“uint”,format=“Color”,inherit=“no”,theme=“spark,mobile”)]
[Style(name=“selectAllBackgroundAlpha”,type=“Number”,inherit=“no”,theme=“spark,mobile”,minValue=“0.0”,maxValue=“1.0”)]
[IconFile(“DropDownList.png”)]
[不鼓励使用企业档案(“移动设备”)]
公共类CheckBoxDropDownList扩展了CheckBoxDropDownList库
{
公共函数CheckBoxDropDownList()
{
超级();
addEventListener(IndexChangeEvent.CHANGE,indexChangeHandler);
}
受保护的函数indexChangeHandler(事件:IndexChangeEvent):void
{
selectedAll=false;
}
[SkinPart(必需=“假”)]
public var selectAllCheckBox:CheckBox;
[SkinPart(必需=“假”)]
公共变量selectAllHitArea:UIComponent;
[SkinPart(必需=“假”)]
公共变量标签显示:IDisplayText;
私有变量labelChanged:Boolean=false;
私有变量labelDisplayExplicitWidth:Number;
私有变量labelDisplayExplicitHeight:Number;
私有变量SizeSetByTypeCalItem:布尔值;
重写公共函数get baselinePosition():编号
{
返回零件的getBaselinePositionForPart(标签显示为IVisualElement);
}
私有变量_提示符:String=“”;
[可检查(category=“General”,defaultValue=”“)]
公共函数get prompt():字符串
{
返回提示;
}
公共函数集提示(值:字符串):无效
{
如果(_prompt==值)
返回;
_提示=值;
labelChanged=true;
无效属性();
}
[可检查(category=“Data”)]
重写公共函数集typicalItem(值:Object):void
{
super.typicalItem=值;
无效化();
}
重写受保护的函数commitProperties():void
{
super.commitProperties();
如果(标签已更改)
{
labelChanged=false;
updateLabelDisplay();
}
如果(已选择全部更改)
{
selectedAllChanged=false;
如果(选择全部复选框)
{
selectAllCheckBox.selected=\u selectedAll;
此.dispatchEvent(新事件(“selectAllChanged”);
}
无效列表();
}
}
覆盖受保护的函数partAdded(partName:String,instance:Object):void
{
super.partAdded(partName,instance);
如果(实例==labelDisplay)
{
labelChanged=true;
无效属性();
}
如果(实例==selectAllCheckBox)
{
selectedAllChanged=true;
无效属性();
}
如果(实例==selectAllHitArea)
{
选择AllHitArea.addEventListener(MouseeEvent.CLICK,选择AllHitArea\u clickHandler);
}
}
覆盖受保护的函数partRemoved(partName:String,instance:Object):void
{
super.partRemoved(partName,instance);
如果(实例==selectAllHitArea)
{
选择AllHitArea.removeEventListener(MouseeEvent.CLICK,选择AllHitArea\u clickHandler);
}
}
受保护函数selectAllHitArea\u clickHandler(事件:MouseeEvent):无效
{
如果(选择全部复选框)
selectedAll=!selectAllCheckBox.selected;
}
私有变量_selectedAll:Boolean=false;
私有变量selectedAllChanged:布尔值;
公共函数get selectedAll():布尔值
{
return _selectedAll;
}
公共函数集selectedAll(值:布尔值):void
{
如果(值==\u选择全部)
返回;
_selectedAll=值;
selectedAllChanged=true;
labelChanged=true;
selectedDices=向量。([]);
//setSelectedItem(未定义,错误);
无效属性();
}
公共函数SetSelectedDices(selValues:Array):无效
{
if(this.dataProvider==null){
返回;
}
变量选择指数:向量。=新向量。();
if(selValues==null | | selValues.length==0)
{
this.selectedAll=true;
返回;
}
for(var i:int=0;i