diff --git a/cocos/scripting/js-bindings/script/jsb_boot.js b/cocos/scripting/js-bindings/script/jsb_boot.js index 09b4123a9c8f..7f3eaaf8146c 100644 --- a/cocos/scripting/js-bindings/script/jsb_boot.js +++ b/cocos/scripting/js-bindings/script/jsb_boot.js @@ -625,15 +625,18 @@ cc.loader = { } var basePath = loader.getBasePath ? loader.getBasePath() : self.resPath; var realUrl = self.getUrl(basePath, url); - var data = loader.load(realUrl, url); - if (data) { - self.cache[url] = data; - cb(null, data); - } else { - self.cache[url] = null; - delete self.cache[url]; - cb(); - } + + loader.load(realUrl, url, item, function (err, data) { + if (err) { + cc.log(err); + self.cache[url] = null; + delete self.cache[url]; + cb(); + } else { + self.cache[url] = data; + cb(null, data); + } + }); }, /** @@ -776,13 +779,18 @@ cc.loader = { * Release the cache of resource by url. * @param url */ - release : function(url){//do nothing in jsb + release : function(url){ + var cache = this.cache; + delete cache[url]; }, /** * Resource cache of all resources. */ - releaseAll : function(){//do nothing in jsb + releaseAll : function(){ + var locCache = this.cache; + for (var key in locCache) + delete locCache[key]; } }; diff --git a/cocos/scripting/js-bindings/script/jsb_loaders.js b/cocos/scripting/js-bindings/script/jsb_loaders.js index 9ef7ec5900b3..1259e1a6c69c 100644 --- a/cocos/scripting/js-bindings/script/jsb_loaders.js +++ b/cocos/scripting/js-bindings/script/jsb_loaders.js @@ -27,7 +27,8 @@ // cc._emptyLoader = { - load : function(realUrl, url){ + load : function(realUrl, url, res, cb){ + cb && cb(null, null); return null; } }; @@ -39,21 +40,25 @@ cc.loader.register([ cc._emptyLoader); cc._txtLoader = { - load : function(realUrl, url){ - return jsb.fileUtils.getStringFromFile(realUrl); + load : function(realUrl, url, res, cb){ + var result = jsb.fileUtils.getStringFromFile(realUrl); + cb && cb(null, result); + return result; } }; cc.loader.register(["txt", "xml", "vsh", "fsh", "tmx", "tsx"], cc._txtLoader); cc._jsonLoader = { - load : function(realUrl, url){ - var data = jsb.fileUtils.getStringFromFile(realUrl); + load : function(realUrl, url, res, cb){ + var data = jsb.fileUtils.getStringFromFile(realUrl), result; try{ - return JSON.parse(data); + result = JSON.parse(data); }catch(e){ cc.error(e); - return null; + result = null; } + cb && cb(null, result); + return result; } }; cc.loader.register(["json", "ExportJson"], cc._jsonLoader); @@ -73,16 +78,20 @@ cc._imgLoader = { cc.loader.register(["png", "jpg", "bmp","jpeg","gif"], cc._imgLoader); cc._plistLoader = { - load : function(realUrl, url){ + load : function(realUrl, url, res, cb){ var content = jsb.fileUtils.getStringFromFile(realUrl); - return cc.plistParser.parse(content); + var result = cc.plistParser.parse(content); + cb && cb(null, result); + return result; } }; cc.loader.register(["plist"], cc._plistLoader); cc._binaryLoader = { - load : function(realUrl, url){ - return cc.loader.loadBinarySync(realUrl); + load : function(realUrl, url, res, cb){ + var result = cc.loader.loadBinarySync(realUrl); + cb && cb(null, result); + return result; } }; cc.loader.register(["ccbi"], cc._binaryLoader); @@ -166,9 +175,12 @@ cc._fntLoader = { return fnt; }, - load : function(realUrl, url){ - var data = jsb.fileUtils.getStringFromFile(realUrl); - return this.parseFnt(data, url); + load : function(realUrl, url, res, cb){ + var data = jsb.fileUtils.getStringFromFile(realUrl), result = null; + if (data) + result = this.parseFnt(data, url); + cb && cb(null, result); + return result; } }; cc.loader.register(["fnt"], cc._fntLoader);