public class ChildClass extends MovieClip
{
public function ChildClass()
{
}
public function aChildClassFunction()
{
}
}
public class AnotherChildClass extends MovieClip
{
public function ChildClass()
{
}
public function aChildClassFunction()
{
}
}
一些要求 childClass 的随机函数(但懒惰的程序员只使用 MovieClip 类)
public function setChildClassInstance(var mc:MovieClip)
{
// How come "mc" represent and be allowed as parameter ??? It's a super-class.. ie. structurally a sub-set of child-class.
mc.aChildClassFunction(); //<< Would generate run-time error for 2nd function call.
}
上述函数也可用于任何 MovieClip 实例
var childClassInstance:ChildClass ;
var anotherChildClassInstance:AnotherChildClass ;
setChildClassInstance( childClassInstance ) // <<<<<VALID, .... NO COMPILER ERROR
setChildClassInstance( anotherChildClassInstance )
//<<< VALID, NO COMPILER ERROR .. BUT WILL CAUSE RUNTIME ERROR !!!!
//
//
//
我想知道,为什么允许超级类(此处为电影剪辑)并将自己表示为子类的参数(此处:ChildClass、AnotherChildClass)。特别是因为,“SUPERCLASSES”实际上是其 PARENT-SET 的“SUB-SET”,即。他们的孩子班。
谢谢