[]小游戏子域程序加载到图集后,取图集内资源报错。

MsgMgr.instance.init();
Laya.timer.once(1000,this,function():void{
beginLoad();
});
private function beginLoad():void
{
Laya.loader.load("res/images/rank.json", Handler.create(this, onLoaded));
}
private function onLoaded():void
{
trace("加载成功");
var c:Image = new Image("rank/country.png");
Laya.stage.addChild(c);
}
 以上是子域项目中加载图集和取资源的代码。代码是参照 https://ask.layabox.com/question/15086 这个帖子的。
图集加载是ok的,但是这样new Image("rank/country.png");从图集里取资源就报错。报错如下。
QQ图片20180830171821.png
已邀请:

Charles

赞同来自:

顶。

Charles

赞同来自:

有没有人能回复一下啊?

Laya_XS

赞同来自:

换外网最新的引擎,已经提供了单独支持的接口,可以测试下:https://ldc.layabox.com/layado ... 0beta

Laya_XSN

赞同来自:

基于md5报错的问题,临时代码的解决方案,下个版本修复,参考代码:
/**
* 传递图集url地址到
* @param url 为绝对地址
*/
public static function sendAtlasToOpenDataContext(url:String):void
{
if(!MiniAdpter.isZiYu)
{
var atlasJson:Object = Loader.getRes(URL.formatURL(url));
if(atlasJson)
{
var textureArr:Array = (atlasJson.meta.image as String).split(",");

//构造加载图片信息
if (atlasJson.meta && atlasJson.meta.image) {
//带图片信息的类型
var toloadPics:Array = atlasJson.meta.image.split(",");
var split:String = url.indexOf("/") >= 0 ? "/" : "\\";
var idx:int = url.lastIndexOf(split);
var folderPath:String = idx >= 0 ? url.substr(0, idx + 1) : "";
for (var i:int = 0, len:int = toloadPics.length; i < len; i++) {
toloadPics[i] = folderPath + toloadPics[i];
}
} else {
//不带图片信息
toloadPics = [url.replace(".json", ".png")];
}
for(i = 0;i<toloadPics.length;i++)
{
var tempAtlasPngUrl:String = toloadPics[i];
postInfoToContext(url,tempAtlasPngUrl,atlasJson);
}
}else
{
throw "传递的url没有获取到对应的图集数据信息,请确保图集已经过!";
}
}
}

private static function postInfoToContext(url:String,atlaspngUrl:String,atlasJson:Object):void
{
var postData:Object = {"frames":atlasJson.frames,"meta":atlasJson.meta};
var textureUrl:String = atlaspngUrl;
var fileObj:Object = MiniFileMgr.getFileInfo(URL.formatURL(atlaspngUrl));
if(fileObj)
{
var fileMd5Name:String = fileObj.md5;
var fileNativeUrl:String = MiniFileMgr.getFileNativePath(fileMd5Name);
}else
{
fileNativeUrl = textureUrl;//4M包使用
}
if(fileNativeUrl)
{
__JS__('wx').postMessage({url:url,atlasdata:postData,imgNativeUrl:fileNativeUrl,imgReadyUrl:textureUrl,isLoad:"opendatacontext"});
}else
{
throw "获取图集的磁盘url路径不存在!";
}
}

要回复问题请先

商务合作
商务合作