How do I test if a property exists on a object before reading its value?

Posted by Jeremy Rudd on Stack Overflow See other posts from Stack Overflow or by Jeremy Rudd
Published on 2010-05-02T06:47:25Z Indexed on 2010/05/02 6:57 UTC
Read the original article Hit count: 240

Filed under:
|
|

I'm attempting to read a property on a series of Sprites. This property may or may not be present on these objects, and may not even be declared, worse than being null.

My code is:

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

And so Flash shows me:

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

Is there a way to test if a property exists before reading its value?

Something like:

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

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about sprite