swf not updating when file xml and swf not in the same domain

旧时模样 提交于 2019-12-25 02:26:39

问题


xml, and i want to get data from external file xml in remote server using AS3, My problem is data xml is showing in consol (trace (data)) but not showing in swf file. if the swf and xml are in the same domain there is no problem.

my crossdomain

<?xml version="1.0" encoding="utf-8" ?>
    <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
    <cross-domain-policy>
        <allow-access-from domain="*" />
        <site-control permitted-cross-domain-policies="by-content-type"/>
        <allow-http-request-headers-from domain="*" headers="*"/>
    </cross-domain-policy>

and my code as3.

`
import flash.text.TextField;
import flash.system.Security;

//var p:TextField = new TextField(); 
//Security.allowDomain("my.domain.com");

Security.loadPolicyFile("http://my.domain.com/crossdomain.xml");
var myXML:XML = new XML();
var myLoader:URLLoader = new URLLoader();
myLoader.addEventListener(Event.COMPLETE, processXML);
myLoader.load(new URLRequest("http://my.domain.com/dataxml.xml?nocache="+Math.random()*28));
function processXML(e:Event):void {
    myXML = XML(e.target.data);
    p.text=myXML.IMAGE[1].@TITLE; 
    //trace(p);
    //addChild(p);
    for (var i:int = 0; i<myXML.*.length(); i++){
        trace("My image number is " + (i+1) + ", it's title is " + myXML.IMAGE[i].@TITLE + " and it's URL is " + myXML.IMAGE[i]);
        trace("----------------"+myXML.IMAGE[i].@TITLE);
    };

}`

回答1:


Yes, when you run your swf in Flash authoring (swf on your computer), it will be able to consume an XML from any domain.

XML gets blocked when the swf is on DomainA.com, and the xml is on DomainB.com UNLESS there's a cross domain policy that says it's ok for another domain to use the xml.

You have to substitute the proper urls in your code.

http://my.domain.com/dataxml.xml is an example url.

Note that my.domain.com is just an example, i set my owner domain in my file .fla.



来源:https://stackoverflow.com/questions/25066552/swf-not-updating-when-file-xml-and-swf-not-in-the-same-domain

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