我正在尝试将一些xml嵌入到我的应用程序中,但是我收到以下错误
Fault] exception, information=TypeError: Error #1090: XML parser failure: element is malformed.
这是我的代码。
package
{
import com.objects.EngineApi;
import com.objects.Rectangles;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
/**
* ...
* @author Anthony Gordon
*/
public class Main extends Sprite
{
[Embed(source = "com/files/level1.xml", mimeType = "application/octet-stream")]
private var theClass:Class;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
var xmlObj:Object = new theClass();
trace(xmlObj);
var xml:XML = new XML(xmlObj) as XML;
}
}
}
xml代码
< STAGE>
< OBJECTS>
< BLOCK X="2" Y="23" WIDTH="36" HEIGHT="4" />
< SPAWN X="6" Y="22" />
< BLOCK X="12" Y="21" WIDTH="4" HEIGHT="2" />
< TUTORIAL X="18" Y="16" TEXT="..." />
< TUTORIAL X="28" Y="22" TEXT="..." />
< BLOCK X="36" Y="2" WIDTH="2" HEIGHT="16" />
< JUMPTHRU X="32" Y="9" WIDTH="4" />
< BLOCK X="27" Y="9" WIDTH="5" HEIGHT="2" />
< COIN X="28" Y="7" />
< COIN X="30" Y="7" />
< COIN X="32" Y="7" />
< COIN X="34" Y="7" />
< BLOCK X="17" Y="8" WIDTH="5" HEIGHT="2" />
< BLOCK X="2" Y="9" WIDTH="10" HEIGHT="2" />
< CHEST X="19" Y="7" COINS="5" />
< DOOR X="5" Y="8" />
< BLOCK X="37" Y="20" WIDTH="2" HEIGHT="3" />
< BLOCK X="1" Y="5" WIDTH="3" HEIGHT="4" />
< BIRD_GOLD X="2" Y="4" COINS="3" TIME="5" />
</ OBJECTS>
</ STAGE>
答案 0 :(得分:0)
这是一个运行时错误,意味着实际的嵌入工作正常,但xml-parser在读取时会出现问题。这可能意味着许多事情,要么标记错误开始,你读错了,或者实际的嵌入会以某种方式打破xml。
我敢打赌,这就是问题所在:
var xmlObj:Object = new theClass();
trace(xmlObj);
var xml:XML = new XML(xmlObj) as XML;
这可能会跟踪[Object object]或类似的内容,这与Flash将尝试解析为XML的字符串相同。
我现在无法测试,尝试将嵌入的mimetype设置为“text / xml”并改为:
var xml:XML = new theClass;