AS3 reflection. How do I know if a method has been canceled?

Can I use AS3 reflection to find out if the method has been overridden?

I need a method like:

protected function isOverriden(methodName:string) : bool
{
    //magic here!
    //...

    return awesomeLocalVariable;
}

So, I pass the method name as a string, and the isOverridden method returns true only if and only if the object has a method of this name and is overridden from its original implementation.

Any idea on how to encode the magic there?

Thanks.

Edit: As requested, the context of the problem:

AS3. "" , , . (onClick, onUpdate, onShapeCollision ..). Component, , , ().

:

    public class CTrace extends ScriptComponent
    {
            public override function onClick(event:MouseEvent = null):void
            {
                    trace(Owner.Id);
            }
    }

onClick MouseEvent.CLICK, .

? , , , .

?

+3
2

. , . , , , . - , , โ€‹โ€‹, , . , , , .

/**
 * Returns true only if the method name given is declared by
 * the source class, and any parent class.
 */
static public function isOverridden(source:*, methodName:String):Boolean {
    var parentTypeName:String = getQualifiedSuperclassName(source);
    if (parentTypeName == null) {
        return false;
    }//if

    var typeName:String = getQualifiedClassName(source);
    var typeDesc:XML = describeType(getDefinitionByName(typeName));
    var methodList:XMLList = typeDesc.factory.method.(@name == methodName);

    if (methodList.length() > 0) {
        //Method exists
        var methodData:XML = methodList[0];
        if (methodData.@declaredBy == typeName) {
            //Method is declared in self
            var parentTypeDesc:XML = describeType(getDefinitionByName(parentTypeName));
            var parentMethodList:XMLList = parentTypeDesc.factory.method.(@name == methodName);
            return parentMethodList.length() > 0;
        }//if
    }//if

    return false;
}//isOverridden

, :

import flash.utils.describeType;
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
import flash.utils.getQualifiedSuperclassName;

:

trace(isOverridden(ChildrenClass, "overriddenMethod")); //true
trace(isOverridden(ChildrenClass, "onlyChildMethod")); //false
trace(isOverridden(ChildrenClass, "onlyParentMethod")); //false
+2

,

overriden = (this[stringNameOfMethod] instanceOf Function && super[stringNameOfMethod] instanceOf Function);

, describeType. , "declareBy". !

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#describeType()

, CS3 Flash-, , . .

0

Source: https://habr.com/ru/post/1723295/


All Articles