简体   繁体   中英

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

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM