Multiple Inheritance in ActionScript 3

前端 未结 4 1119
半阙折子戏
半阙折子戏 2021-02-06 05:50

Multiple Inheritance in ActionScript 3? Is it possible? I have read somewhere that it is possible in as3.

If yes then how?

this is my Doucument Class A.as

<
4条回答
  •  臣服心动
    2021-02-06 06:51

    You can do the multiple inheritance using the interface.

    1. Define Class A,B and C. and Define interface for the Class B and C respectively iB and iC.
    2. Just extends the Class C to Class A using "extend" keyword - Direct Inheritance of class
    3. extends your interface iC to the interface iB.
    Just check code as per your requirement:
    
    package
    {
      import flash.display.MovieClip;
      public class A extends MovieClip implements B
      {
          public var value1:Number=10;
          public function A()
          {
              trace("A Class Constructor");
          }
          public function hit():void
          {
              trace(value1+' from hit');
          }
          public function print():void
          {
              trace("Print Method Called");
          }
      }
    } 
    
    package
    {
      public interface B extends D 
      {
          function hit():void;
      }
    }
    
    package
    {
      public class C implements D
      {
          pulic function C()
          {
              trace("C Class Constructor");
          }
          public function print():void
          {
              trace("Print Method Called");
          }
      }
    }
    
    package
    {
      public interface D
      {
          function print():void;
      }
    }
    

提交回复
热议问题