<!--
如何在其他程序文件onload时访问静态对象的方法
var xmlUtil = cc.Class({
// extends: cc.Component,
properties: {
xmlName:null,
data:null
},
statics: {
instance: null
},
ctor: function () {
this.xmlName = [// 新表加入时需加入对应表名
"ExampleData",
"battle1",
"battle2",
"battle3",
"battle4",
"battle5",
"battle6",
"battle7",
"battle8",
];
var index = 0;
var aLen = this.xmlName.length;
var xName = this.xmlName;
var alldata = [];
var addData = function(){
if(index<aLen){
var url = cc.url.raw('resources/'+xName[index]+'.json');
cc.loader.load( url, function(err, res){
if(err){
cc.log("Error"+err);
}else{
alldata[xName[index]] = res;
}
index++;
addData();
});
};
};
addData();
this.data = alldata;
},
getXmlInfo: function (name, id){
cc.log("----------get data!-----------");
cc.log(name+"------------")
var newdata = this.data[name];
if (newdata == null){
cc.log("there is no xml named "+name);
return null;
}
if (newdata[id] == null){
cc.log("there is no xmlinfo by id "+id+"in "+name)
return null;
}
return newdata[id];
},
getLen: function(name){
var Length = 0;
for(var item in this.data[name]){
Length++;
}
return Length;
},
getAllXmlInfo: function(name){
var newdata = this.data[name];
if (newdata == null){
cc.log("there is no statictable named "+name)
return null
}
return newdata
}
});