LayaBox:子節點的class類調用父節點(兄弟節點)class類的公共方法和公共屬性解決方案

層級關系:test(父級) 、 testComponent(子級)

test.ui包含組件testComponent.ui

代碼示例:

//父級代碼:
class Test extends ui.testUI{
      constructor(){
         super();
                //將自己傳過去給子節點的類
                 this.component.setTestObj(this);
      }
      public jhHandler():void{
           //設置按鈕的屬性變灰
           this.ActiveBtn.gray=true;
      }
}

//子級代碼
class TestComponent extends ui.testComponentUI{
       constructor(){
         super();
      }
      //保存父級的對象應用
      public test:Test;
      public setTestObj(test:Test):void{
              this.test=test;
      }
      //通過引用調用父節點類的方法
      public handler():void{
            this.test. jhHandler();
      }
}

注意:兄弟節點類的相互引用雷同

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容