Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.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 AS3组合框是空的吗?_Actionscript 3 - Fatal编程技术网

Actionscript 3 AS3组合框是空的吗?

Actionscript 3 AS3组合框是空的吗?,actionscript-3,Actionscript 3,我有一个onChange事件,我想测试组合框是否为空,如果为空,我想更改组合框的颜色。我可以找到一个值,例如“Fred Bloggs”,但不能测试它是否为空: if (e.target.selectedItem.label == ""){ // This doesn't work trace("EMPTY"); my_color.color = 0x002222; instructorList.transform.colorTransform = my_color; } 如果未选择

我有一个onChange事件,我想测试组合框是否为空,如果为空,我想更改组合框的颜色。我可以找到一个值,例如“Fred Bloggs”,但不能测试它是否为空:

if (e.target.selectedItem.label == ""){ // This doesn't work
      trace("EMPTY");
my_color.color = 0x002222;
instructorList.transform.colorTransform = my_color;
}

如果未选择任何项目,selectedItem属性将为空:

comboBox.addEventListener(MouseEvent.CLICK, mouseHandler);

function mouseHandler(e:MouseEvent) {
    if (e.currentTarget.selectedItem == null){ // This doesn't work
        trace("EMPTY");
        my_color.color = 0x002222;
        instructorList.transform.colorTransform = my_color;
    }
}
注意:如果组合框中没有项目,则不会触发CHANGE事件,因为无法将其“更改”为任何内容。相反,将此测试添加到单击处理程序中

<强> Update:< /强>在下面的注释中给出新信息,简单地测试索引是否与列表顶部的空白项匹配。

    if (e.currentTarget.selectedIndex == 0) {
        trace("EMPTY");
        my_color.color = 0x002222;
        instructorList.transform.colorTransform = my_color;
    }

只有当用户启动更改时,才会调度flex更改事件。如果更改是由用户发起的,则不会为null。如果要查找空值,请尝试valueCommit属性/事件。

我尝试了,但没有成功。我在标签和数据上都尝试过,但没有任何更改。问题是您使用了错误的EventHandler,我更新了答案以提供帮助。唯一的空值位于列表顶部。基本上,它在更改之前是空白的。我想检查它什么时候变为空白,如果这有意义的话。对不起,我误解了你的意思。我以为你在测试组合框中是否没有项目。我已经更新了我的答案来测试组合框是否已经选择了顶部项目(即空白项目)。但是,当有一个值时,它不应该被火,然后变为没有价值吗?(Flex与Flash AS3完全相同吗?@user1203605是的,如果这是combobox“数据提供程序”中的选项之一。@user1203605为什么不将其与combobox.selectedLabel进行比较,而不是与event.target.selectedItem.label进行比较?