开发者

AS3 test for Class type

开发者 https://www.devze.com 2023-03-21 16:46 出处:网络
I have a function which is giving me the 开发者_StackOverflow社区class type of an object that I pass in.

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

精彩评论

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