I really get confused with these type of statements :
What does this mean :
-
when casting :
var xyz = ClassA( obj as MovieClip ); -
when declaring/defining :
var xyz:ClassA = new SomeOtherClass();
I mean, how 2 different classes are used in the same statements above ? Is this possible because of inheritance relationship ?
Thanks
V.
xyz is declared as having the type ClassA, so this assignment will only work if SomeOtherClass is a subclass of ClassA. If not, an error will be thrown at compile time.
The result of this statement is a double cast: First, obj is cast to MovieClip, then to ClassA. If any of those two types is not in obj’s type hierarchy, the result is
null.Unless obj is not a MovieClip (in which case, trying to cast
nullto ClassA will cause a null pointer exception at runtime), there will not be an error, because you could assign anything to xyz – no variable type was specified.