Utility Functions For AS3 Classes
/**
*   Get a class by its fully-qualified name
*   @param className Fully-qualified name of the class
*   @return The class with the given name or null if none exists
*   @author Jackson Dunstan
*/
public static function getClassByName(className:String): Class
{
    try
    {
        return Class(getDefinitionByName(className));
    }
    catch (refErr:ReferenceError)
    {
        return null;
    }
    catch (typeErr:TypeError)
    {
        return null;
    }
 
    return null;
}
/**
*   Get the class of an object
*   @param obj Object to get the class of
*   @return The class of the given object or null if the class cannot be
*           determined
*   @author Jackson Dunstan
*/
public static function getClass(obj:Object): Class
{
    if (obj == null)
    {
        return null;
    }
    try
    {
        var className:String = getQualifiedClassName(obj);
        var ret:Class = Class(getDefinitionByName(className));
        if (ret == null && obj is DisplayObject)
        {
            ret = getDisplayObjectClass(DisplayObject(obj));
        }
        return ret;
    }
    catch (refErr:ReferenceError)
    {
        return null;
    }
    catch (typeErr:TypeError)
    {
        return null;
    }
 
    return null;
}
 
/**
*   Get the class of a display object
*   @param obj Object to get the class of
*   @return The class of the given object or null if the class cannot be
*           determined
*   @author Jackson Dunstan
*/
public static function getDisplayObjectClass(obj:DisplayObject): Class
{
    try
    {
        return Class(obj.loaderInfo.applicationDomain.getDefinition(getQualifiedClassName(obj)));
    }
    catch (refErr:ReferenceError)
    {
        return null;
    }
    catch (typeErr:TypeError)
    {
        return null;
    }
 
    return null;
}
作者:ywxgod
E-mail:给我发邮件
出处:http://ywxgod.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
E-mail:给我发邮件
出处:http://ywxgod.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号