1

Say you have an object,

var obj:Object = someOtherObject;

And you need to check if it is of the type with the name stored in myString

var myString:String = someOtherString; // ex. "int", "Number", "CustomClass"

I have tried:

if(obj is getDefinitionByName(myString))

But that doesn't seem to work. How would you go about doing this?

4

1 回答 1

1

这对我有用:

var obj:Object = 5;

var myString:String = "int";

var c:Class = getDefinitionByName(myString) as Class;
if (c && obj is c)
{
    trace("obj is of type "+myString);
}

getDefinitionByName 的返回类型是 Object,因此将其转换为 Class 似乎可以解决问题。

于 2012-07-14T18:56:36.760 回答