XML data can't be read by swf file when i publish it

陌路散爱 提交于 2019-12-30 07:44:08

问题


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>

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;
}

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.

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>

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()

回答1:


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>

and i call this file in my flash file like this :

Security.loadPolicyFile("http://localhost:15979/crossdomain.xml");

and every thing works fine .



来源:https://stackoverflow.com/questions/25830188/xml-data-cant-be-read-by-swf-file-when-i-publish-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!