ActionScript - 在switch语句中使用"is"比较?

The*_*978 2 actionscript-3 switch-statement

我有许多相同自定义类的对象,以及另一个自定义类的另一个对象.我想创建一个switch语句来确定该对象属于哪个类.以下代码无法编译,所以我不确定这是否可行.是使用if语句的唯一选择吗?

function mouseClickEventHandler(evt:MouseEvent):void
     {
     switch (evt.currentTarget)
            {
            case (is customClassA):  trace("is instance of customClassA");  break
            case (is customClassB):  trace("is instance of customClassB");
            }
     }
Run Code Online (Sandbox Code Playgroud)

pok*_*oke 12

这应该工作:

function mouseClickEventHandler ( evt:MouseEvent ):void
{
    switch ( evt.currentTarget.constructor )
    {
        case CustomClassA:
            trace("is instance of customClassA");
            break;

        case CustomClassB:
            trace("is instance of customClassB");
            break;
    }
}
Run Code Online (Sandbox Code Playgroud)

请参见Object.constructor.