ActionScript: Using 'in' on protected/private variables?

Posted by David Wolever on Stack Overflow See other posts from Stack Overflow or by David Wolever
Published on 2010-04-08T17:18:04Z Indexed on 2010/04/08 17:23 UTC
Read the original article Hit count: 164

Filed under:

Is there any way to mimic the in operator, but testing for the existence of protected or private fields?

For example, this:

<mx:Script><![CDATA[
    public var pub:Boolean = true;
    protected var prot:Boolean = true;
    private var priv:Boolean = true;
]]></mx:Script>

<mx:creationComplete><![CDATA[
    for each (var prop in ["pub", "prot", "priv", "bad"])
        trace(prop + ":", prop in this);
]]></mx:creationComplete>

Will trace:

pub: true
prot: false
priv: false
bad: false

When I want to see:

pub: true
prot: true
priv: true
bad: false

© Stack Overflow or respective owner

Related posts about actionscript