Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AS3 test for Class type

I have a function which is giving me the 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

like image 967
crooksy88 Avatar asked Jul 19 '11 16:07

crooksy88


2 Answers

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.

like image 52
Peter Avatar answered Oct 24 '22 03:10

Peter


You should not use is but == ;)

Because getClass(panelStack[0]) is Class

like image 6
Kodiak Avatar answered Oct 24 '22 03:10

Kodiak