SWF不更新时,文件中的XML和SWF不在同一个域中 [英] swf not updating when file xml and swf not in the same domain

查看:203
本文介绍了SWF不更新时,文件中的XML和SWF不在同一个域中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XML,我想用AS3获取远程服务器从外部文件的XML数据,我的问题是数据的XML是显示在CONSOL(跟踪(数据)),但没有显示在SWF文件。如果瑞士法郎和xml都在同一域中也没有问题。

我的跨域

 < XML版本=1.0编码=UTF-8&GT?;
    <!DOCTYPE跨域政策体系http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
    <交域政策>
        <允许存取来自域=*/>
        <现场控制允许交叉域策略=由内容型/>
        <允许-HTTP请求报头,从域=*标题=*/>
    < /跨域策略>
 

和我的code AS3。

 `
进口API元素flash.text.TextField;
进口类flash.system.Security;

// VAR号码:文本字段=新的TextField();
//Security.allowDomain("my.domain.com);

在Security.loadPolicyFile(http://my.domain.com/crossdomain.xml);
VAR与myXML:XML =新的XML();
VAR myLoader:的URLLoader =新的URLLoader();
myLoader.addEventListener(引发Event.COMPLETE,的processXML);
myLoader.load(新的URLRequest(http://my.domain.com/dataxml.xml?nocache=+的Math.random()* 28));
功能的processXML(五:事件):无效{
    与myXML = XML(e.target.data);
    p.text = myXML.IMAGE [1] @ TITLE。
    //迹(对);
    //的addChild(对​​);
    对于(VAR我:= 0; I<与myXML *长度();我++){
        迹线(我的图像编号为+第(i + 1)+,它的标题为+ myXML.IMAGE [I] @标题+和它的URL是+ myXML.IMAGE [I]);
        跟踪(----------------+ myXML.IMAGE [I] @称号。);
    };

}`
 

解决方案

是的,当你(在您的计算机上的SWF)运行Flash创作您的SWF,它可以从任何域消耗的XML。

XML被阻塞时,SWF是DomainA.com,并且XML是DomainB.com除非有一个跨域策略,说这是确定的另一个域使用XML。

您需要替换正确的URL在code。

http://my.domain.com/dataxml.xml 是一个例子网址。

请注意, my.domain.com 只是一个例子,我把我的老板域在我的文件中的.fla

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

}`

解决方案

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.

这篇关于SWF不更新时,文件中的XML和SWF不在同一个域中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆