如何处理异步事件的回调,比如http请求
场景:
onEnter: function(){
this._super();
var self = this;
this._listener1 = cc.EventListener.create({
event: cc.EventListener.CUSTOM,
eventName: "HttpEvent",
callback: function(event){
self.onHttpEvent(event.getUserData());
}
});
cc.eventManager.addListener(this._listener1, 1);
},
onExit: function(){
cc.eventManager.removeListener(this._listener1);
this._listener1 = null;
this._super();
},
异步调用:
var event = new cc.EventCustom("HttpEvent");
var userData = {sender: this, type: 1, param: "param"};
event.setUserData(userData);
cc.eventManager.dispatchEvent(event);
[javascript] view plain copy
2023-12-06 广告