我希望业务逻辑同步的创建和删除一个UI对象,但是UI本身的加载是异步的。因此我将load方法放到了createChildren函数里面去。
class MyView extends ui.view.MyViewUI {
constructor() {
super();
}
createChildren():void {
super.createChildren();
let assets = [
{ url: "res/atlas/ui/shared.atlas", type: Loader.ATLAS },
{ url: "res/atlas/ui/myview.atlas", type: Loader.ATLAS },
{ url: "view/MyView.json", type: Loader.JSON },
]
Laya.loader.load(assets, Handler.create(this, this.onLoaded));
}
private onLoaded():void {
this.createView(Laya.loader.getRes("view/MyView.json"));
}
}
因为加载是异步的,很有可能在加载过程中,用户或者其他行为逻辑已经反复开关这个界面多次了。是否意味着onLoaded会多次回调回来。如何判断过滤那些已经失效的onLoaded,在里面判断this.stage么?