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();
      }
}

注意:兄弟节点类的相互引用雷同

你可能感兴趣的:(LayaBox:子节点的class类调用父节点(兄弟节点)class类的公共方法和公共属性解决方案)