Row*_*wan 1 flash inheritance actionscript actionscript-3
在AS3中,我试图检查一个对象是一个实例,还是扩展一个特定的类.if (object is ClassName)如果对象是实例,则使用类似的工作,ClassName但如果它是扩展 的类的实例则不使用ClassName.
伪代码示例:
class Foo {}
class Bar extends Foo {}
var object = new Bar();
if (object is Foo){ /* not executed */ }
if (object is Foo){ /* is executed */ }
Run Code Online (Sandbox Code Playgroud)
我想要的东西:
class Foo {}
class Bar extends Foo {}
var object = new Bar();
if (object is Foo){ /* is executed */ }
Run Code Online (Sandbox Code Playgroud)
任何人的想法?
package {
import flash.display.Sprite;
public class Main extends Sprite {
public function Main() {
var bar:Bar=new Bar();
trace("bar is Bar",bar is Bar);//true
trace("bar is Foo:",bar is Foo);//true
trace("bar is IKingKong:",bar is IKingKong);//true
trace(describeType(bar));
//<type name="Main.as$0::Bar" base="Main.as$0::Foo" isDynamic="false" isFinal="false" isStatic="false">
//<extendsClass type="Main.as$0::Foo"/>
//<extendsClass type="Object"/>
//<implementsInterface type="Main.as$0::IKingKong"/>
//</type>
}
}
}
interface IKingKong{}
class Foo implements IKingKong{}
class Bar extends Foo{}
Run Code Online (Sandbox Code Playgroud)