as 从接口继承

从接口继承:

//AS3 不支持抽象类, 但支持接口
//接口只能使用 public 和 internal 访问控制说明符
//接口不能包含变量或常量,但是可以包含属性
//继承接口的方法时,方法格式须一致, 但参数名和参数的默认值可不同
//继承多个接口时可用逗号隔开
 
//接口, 保存在工程目录下 IBase.as
package {
    public interface IBase {
        function InterfaceMethod(); //接口成员不使用可见性修饰, 都是公开的
    }
}
 
//子类, 保存在工程目录下 CTest.as
package {
    public class CTest implements IBase {
        public function InterfaceMethod() { trace("InterfaceMethod"); }
        public function TestMethod() { trace("TestMethod"); }
    }
}
 
//测试
var obj:CTest = new CTest();
obj.InterfaceMethod(); //InterfaceMethod
obj.TestMethod();      //TestMethod

原文地址:https://www.cnblogs.com/flashweb/p/3528560.html