Type, .
: -
import flash.utils.describeType;
public static function hasSetter( subject : *, propName : String ) : Boolean
{
var desc : XML = describeType( subject );
var access : String = desc.accessor.(@name == propName).@access.toString();
return ( access.indexOf( "write" ) > -1 );
}
public static function hasGetter( subject : *, propName : String ) : Boolean
{
var desc : XML = describeType( subject );
var access : String = desc.accessor.(@name == propName).@access.toString();
return ( access.indexOf( "read" ) > -1 );
}
and tousdan point - if you are going to do this, then create a cache. I don't like to include mx libraries unless I need me to prepare this simple caching:
public static function getTypeDescription( instance : * ) : XML
{
var key : String = getSimpleClassName( instance );
switch( true )
{
case ( typeDescriptions == null ) :
typeDescriptions = new Object();
typeDescriptions[ key ] = describeType( instance );
break;
case ( typeDescriptions[ key ] == null ) :
typeDescriptions[ key ] = describeType( instance );
break;
case ( typeDescriptions[ key ] != null ) :
break;
default :
trace( "\tERROR : unhanded case DataUtils.getTypeDescription." );
return null;
break;
}
return typeDescriptions[ key ] as XML;
}
public static function getSimpleClassName( instance : * ) : String
{
var className : String = String( getClass( instance ) );
className = className.substring( 7, className.length - 1 );
return( className );
}
source
share