我有这段代码,我试图加载一个 JSON 文件并解析它。但是当我尝试用我制作的类加载它(我可以加载图像和声音)时,它给了我这个错误:
Error #2124: Loaded file is an unknown type. URL: http://192.168.1.19/Sheet1.json
这是我用来加载它的函数,我怎样才能让它让 Flash 识别文件类型?
public function LoadString(path:String) {
var stringLoader:flash.display.Loader = new flash.display.Loader();
stringLoader.contentLoaderInfo.addEventListener(LoaderEvent.COMPLETE, loadStringComplete);
stringLoader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpError,false,0,true);
stringLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, error, false, 0 ,true);
stringLoader.load(new URLRequest(path));
}
private function loadStringComplete(e:Event) {
try {
dispatchEvent(new LoaderEvent(LoaderEvent.STRING_LOADED,0,0,e.target.data,true));
} catch (error:*) {
dispatchEvent(new LoaderEvent(LoaderEvent.ERROR,0,0,"Error: "+ error.toString(),true));
}
}
JSON 文件的内容是使用 Flash CS6 中的新 Spritesheet 方法生成的。
{"frames": {
"Front AA0000":
{
"frame": {"x":0,"y":0,"w":12,"h":13},
"rotated": false,
"trimmed": false,
"spriteSourceSize": {"x":0,"y":0,"w":12,"h":13},
"sourceSize": {"w":12,"h":13}
},
"Rot AA0000":
{
"frame": {"x":12,"y":0,"w":14,"h":6},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":14,"y":8,"w":32,"h":14},
"sourceSize": {"w":32,"h":14}
},
"Rot AA0001":
{
"frame": {"x":0,"y":13,"w":20,"h":8},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":9,"y":6,"w":32,"h":14},
"sourceSize": {"w":32,"h":14}
},
"Rot AA0002":
{
"frame": {"x":0,"y":21,"w":28,"h":8},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":4,"y":6,"w":32,"h":14},
"sourceSize": {"w":32,"h":14}
},
"Rot AA0003":
{
"frame": {"x":0,"y":29,"w":24,"h":8},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":4,"y":6,"w":32,"h":14},
"sourceSize": {"w":32,"h":14}
},
"Rot AA0004":
{
"frame": {"x":0,"y":37,"w":28,"h":11},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":0,"y":3,"w":32,"h":14},
"sourceSize": {"w":32,"h":14}
},
"Rot AA0005":
{
"frame": {"x":0,"y":48,"w":28,"h":14},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":14},
"sourceSize": {"w":32,"h":14}
}},
"meta": {
"app": "Adobe Flash CS6",
"version": "12.0.0.481",
"image": "Rocket AA 8-Bit.png",
"format": "RGB8",
"size": {"w":32,"h":64},
"scale": "1"
}
}