gpt4 book ai didi

actionscript-3 - 在读取属性值之前如何测试对象上是否存在属性?

转载 作者:行者123 更新时间:2023-12-02 23:29:42 25 4
gpt4 key购买 nike

我正在尝试读取一系列 Sprite 的属性。该属性可能存在于这些对象上,也可能不存在,甚至可能没有声明,比 null 更糟糕。

我的代码是:

if (child["readable"] == true){
// this Sprite is activated for reading
}

Flash 向我展示了:

Error #1069: Property selectable not found on flash.display.Sprite and there is no default value.

有没有办法在读取属性值之前测试该属性是否存在?

类似于:

if (child.isProperty("readable") && child["readable"] == true){
// this Sprite is activated for reading
}

最佳答案

AS3 中的对象具有 hasOwnProperty方法,它接受一个字符串参数,如果对象定义了该属性,则返回 true

if(myObj.hasOwnProperty("someProperty"))
{
// Do something
}

关于actionscript-3 - 在读取属性值之前如何测试对象上是否存在属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2752688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com