无法在 FlashDevelop 中嵌入 XML
我试图将一些 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>
I am trying to embed some xml into my application but I get the following error
Fault] exception, information=TypeError: Error #1090: XML parser failure: element is malformed.
Here is my code.
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 code
< 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个运行时错误,意味着实际嵌入正在工作,但 xml 解析器在读取它时会发出嘎嘎声。这可能意味着很多事情,要么是标记一开始就是错误的,要么是您读错了,或者是实际的嵌入以某种方式破坏了 xml。
我敢打赌,这就是您的问题所在:
这可能会跟踪为 [Object object] 或类似的内容,这与 Flash 尝试解析为 XML 的字符串相同。
我现在无法测试这一点,请尝试将嵌入的 mimetype 设置为“text/xml”并执行以下操作:
That is a runtime error, meaning the actual embed is working but the xml-parser croaks when reading it. This can mean many things, either that the markup is wrong to begin with, you're reading it wrong or that the actual embed breaks the xml somehow.
My bet is that this is where your problem is:
This will likely trace as [Object object] or something like that, which is the same string Flash will try to parse as XML.
I can't test this right now, byt try setting the mimetype of the embed to "text/xml" and doing like this instead: