当我发布它时,swf 文件无法读取 XML 数据 [英] XML data can't be read by swf file when i publish it
问题描述
我正在尝试从 URL http://localhost:15979/default.aspx
读取数据.该 url 的输出是:
I am trying to read data from a URL http://localhost:15979/default.aspx
.The output of the url is :
<?xml version="1.0" encoding="utf-8"?>
<GALLERY>
<IMAGE TITLE="abs">image1.jpg</IMAGE>
<IMAGE TITLE="iron">image2.jpg</IMAGE>
<IMAGE TITLE="shop">image3.jpg</IMAGE>
</GALLERY>
我使用以下代码将这些值放入adobe flash cs
:
I fetch this values into adobe flash cs
with this code:
var myXML:XML = new XML();
var XML_URL:String = "http://localhost:15979/default.aspx";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):void
{
myXML = XML(myLoader.data);
trace("Data loaded.");
txtname.text=myXML.IMAGE[1].@TITLE;
}
所以当我按下 ctrl +enter
时,swf 文件显示结果并且一切正常,但是当我发布 swf
文件时,我的 XML 文件不能阅读并且 myXML.IMAGE[1].@TITLE;
没有出现在屏幕上.另一个问题是当我更改 xml 时,这些更改不适用于 SWF 文件.
So when i push ctrl +enter
the swf file shows the result and every thing works fine ,but when i publish the swf
file my XML file can't be read and the myXML.IMAGE[1].@TITLE;
doesn't apear on the screen.another problem is when i changed the xml ,the changes don't apply in SWF file.
我将 xml 格式更改为:
I changed the xml form to :
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" secure="false" />
</cross-domain-policy>
<GALLERY>
<IMAGE TITLE="asas">image1.jpg</IMAGE>
<IMAGE TITLE="ssssss">image2.jpg</IMAGE>
<IMAGE TITLE="shop">image3.jpg</IMAGE>
</GALLERY>
但是 .fl 文件抛出这个错误:
But .fl file throws this error :
TypeError: Error #1088: The markup in the document following the root element must be well-formed.
at _3333333333333333333333_fla::MainTimeline/xmlLoaded()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
推荐答案
我终于在我的项目中添加了一个跨域文件,如下所示:
I finally add a cross domain file to my project as you can see here :
<?xml version="1.0" encoding="utf-8" ?>
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="*"/>
<allow-access-from domain="*"/>
</cross-domain-policy>
我在我的 Flash 文件中调用这个文件,如下所示:
and i call this file in my flash file like this :
Security.loadPolicyFile("http://localhost:15979/crossdomain.xml");
一切正常.
这篇关于当我发布它时,swf 文件无法读取 XML 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!