I am not sure if I am missing something here. I would like to compare two classes that uses the same interface. Is this possible? I understand that the is operator compares classes, but is there any similar function when you use interfaces?
// works
var effect1 : CrazyEffect = new CrazyEffect();
var effect2 : SaneEffect = new SaneEffect();
trace(effect1 is effect2) // false
// does not work
var effect1 : ISoundEffect = new CrazyEffect();
var effect2 : ISoundEffect = new SaneEffect();
trace(effect1 is effect2)
1067: Implicit coercion of a value of type ISoundEffect to an unrelated type Class.
Note the differences between concepts of a class and of an object. The former is a data type whereas the latter is a runtime instance of it, a variable.
isoperator can not compare one variable to another.According to language reference
In other words, compiler expects the first operand to be a variable whereas the second operand should be a type identifier.
However
effect2is not a type identifier but a variable. Hence the error message.Unfortunately there is no generic operator to test for interface commonality. The only alternative is:
Update
Checking whether objects are instances of a same class can be done by comparing class names:
For in depth discussion see Get the class used to create an object instance in AS3