简体   繁体   English

Class 类型的 AS3 测试

[英]AS3 test for Class type

I have a function which is giving me the class type of an object that I pass in.我有一个 function ,它给了我 class 类型的 object 我传入。

public function getClass(obj:Object):Class {
return Class(getDefinitionByName(getQualifiedClassName(obj)));
}

Now if I do this现在如果我这样做

trace(getClass(panelStack[0]));

I get [class InfoPanel] in the output window which is correct我在 output window 中得到 [class InfoPanel] 是正确的

But if I do this但如果我这样做

trace(getClass(panelStack[0]) is InfoPanel);

I get false, but I'm expecting true.我是假的,但我期待的是真的。

Could anyone please point out what I'm doing wrong here.谁能指出我在这里做错了什么。 I'm just about to tear the last parts of my hair out!!!我正要撕掉我头发的最后一部分!!!

Thanks,谢谢,

Mark标记

You're almost there, just remove the getClass() call.你快到了,只需删除getClass()调用。 Try this instead:试试这个:

trace(panelStack[0] is InfoPanel);

The is operator can be used with any variable or expression to determine if it is a member of a particular data type. is运算符可以与任何变量或表达式一起使用,以确定它是否是特定数据类型的成员。 When you had made the call to getClass() you were essentially testing against completely different instance.当您调用getClass()时,您实际上是在针对完全不同的实例进行测试。

You should not use is but == ;)你不应该使用is but == ;)

Because getClass(panelStack[0]) is Class因为getClass(panelStack[0]) is Class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM