开发者

AS3 test for Class type

I have a function which is giving me the 开发者_StackOverflow社区class type of an object that I pass in.

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

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. 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. When you had made the call to getClass() you were essentially testing against completely different instance.


You should not use is but == ;)

Because getClass(panelStack[0]) is Class

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜