为什么我的Flex as3 crossdomain.xml不起作用?

时间:2014-10-31 13:40:12

标签: xml actionscript-3 flash flex azure

我花了很多时间试图弄清楚我的crossdomain.xml实现出了什么问题。这里有很多关于他们的问题,我已经尝试过每一个问题。

我正在使用Azure Blob存储来存储我的swf需要访问的图像。此外,我正在使用BulkLoader swc加载这些资产。下面是在应用程序尝试从URL加载图像之前运行的代码。

Security.allowDomain("mydomain.blob.core.windows.net");
Security.allowInsecureDomain("mydomain.blob.core.windows.net");
Security.loadPolicyFile("http://mydomain.blob.core.windows.net/crossdomain.xml");

以下是我尝试过的不同crossdomain.xml配置的示例。我可能尝试了20种不同的配置,但似乎没有任何效果。

1

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

2

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <site-control permitted-cross-domain-policies="master-only" />
  <allow-access-from domain="*" secure="false" />
  <allow-http-request-headers-from domain="*" headers="*" secure="false" />
</cross-domain-policy>

3

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <allow-access-from domain="*"/>
</cross-domain-policy>

这是我在flashlog文件中得到的错误。

*** Security Sandbox Violation ***
SecurityDomain 'http://localhost:81/controller/view' tried to access incompatible
context 'http://mydomain.blob.core.windows.net/crossdomain.xml'

任何帮助将不胜感激。这个问题让我抓狂。提前谢谢。

1 个答案:

答案 0 :(得分:1)

所以我弄清楚我做错了什么。你需要发送一个LoaderContext的bulkLoader,就像你对普通的Loader类一样。这是我用过的代码。加载声音文件时也使用SoundLoaderContext。

var currentSecurityDomain:SecurityDomain = null;
if (Security.sandboxType == Security.REMOTE)
    currentSecurityDomain = SecurityDomain.currentDomain;

var loaderContext = new LoaderContext(true, ApplicationDomain.currentDomain, currentSecurityDomain);

var currentSecurityDomain:SecurityDomain = null;
if (Security.sandboxType == Security.REMOTE)
    currentSecurityDomain = SecurityDomain.currentDomain;

var soundLoaderContext = new SoundLoaderContext(1000, true);

var currentSecurityDomain:SecurityDomain = null;
if (Security.sandboxType == Security.REMOTE)
    currentSecurityDomain = SecurityDomain.currentDomain;

var loaderContext = new LoaderContext(true, ApplicationDomain.currentDomain, currentSecurityDomain);
var soundLoaderContext = new SoundLoaderContext(1000, true);

var bulkLoader:BulkLoader = new BulkLoader("main");
bulkLoader.add(URL, { context: loaderContext, "id":animationID, maxTries:1, priority:priority});
bulkLoader.add(URL_TO_SOUND, { context: soundLoaderContext, "id":animationID, maxTries:1, priority:priority});
bulkLoader.addEventListener(BulkLoader.COMPLETE, onAllItemsLoaded);
bulkLoader.start();