我正在尝试从我的网站上加载我的Flex Mobile应用程序中的图像。当我使用localhost运行代码时,一切都很完美。但是,当我尝试从我的实时网站加载图像时,我收到错误:
IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2036: Load Never Completed. URL: http://sortsports.com/images/players/nfl/sketch/8850x300.jpg" errorID=2036]
我使用Loader加载图像,并使用LoaderContext设置checkPolicyFile为false。
var lc:LoaderContext = new LoaderContext();
lc.checkPolicyFile = false; // bypass security sandbox / policy file - does this effect quality when scaling? - See more at: http://www.onegiantmedia.com/as3--load-a-remote-image-from-any-url--domain-with-no-stupid-security-sandbox-errors#sthash.ZRnTf99k.dpuf
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, playerImageLoadCompleteHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);
trace('loading: ' + remoteFileUrl);
loader.load(new URLRequest(remoteFileUrl), lc); // add a loader context to not check the policy file
private function playerImageLoadCompleteHandler(event:Event):void
{
var loaderInfo:LoaderInfo = event.target as LoaderInfo;
playerImage.source = loaderInfo.content;
}
private function loaderIOErrorHandler(ev:Event):void{
trace("Image not found and ioError: " + ev);
playerImage.source = 'k';
}
我还在网址的根目录中有一个跨域政策:
<?xml version="1.0"?>
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" to-ports="*"/>
</cross-domain-policy>
我像这样加载交叉域:
Security.loadPolicyFile(Globals.currentDomain + "/crossdomain.xml");
我尝试允许域名
//Security.allowDomain('http://sortsports.com/');
但是我收到了错误
SecurityError: Error #3207: Application-sandbox content cannot access this feature.
所以我把它放在try catch中:
try {Security.allowDomain("*");}catch (e) { trace("e.message: " + e.message); };
同样,代码在localhost上运行良好。我不认为使用代理是可能的,因为这是一个移动应用程序。