我试图读取一系列Sprites上的一个属性。这个属性可能存在于这些对象上,也可能没有被声明,更糟糕的是可能为null。
我的代码如下:
if (child["readable"] == true){
// this Sprite is activated for reading
}
因此Flash向我展示:
Error #1069: 在flash.display.Sprite上未找到属性selectable,且没有默认值。
是否有一种方法可以在读取属性值之前测试其是否存在?
例如:
if (child.isProperty("readable") && child["readable"] == true){
// this Sprite is activated for reading
}
readable
在child
的原型中定义而不是实例本身中定义,那么hasOwnProperty
将返回false
(例如,document.hasOwnProperty('getElementById') === false
,而('getElementById' in document) === true
)。 - kennytm