Reputation: 181
I get this error when I run my swf locally (also doesn't work with browser):
SecurityError: Error #2121: Security sandbox violation: LoaderInfo.content: file:///C|/Users/Admin/Desktop/whatever.swf cannot access https://content.mspcdns.com/swf/headwear/story_2022_girlhat_tk.swf. This may be worked around by calling Security.allowDomain.
at flash.display::LoaderInfo/get content()
at Function/com.mspicker.utils:SWFLoader/loadSWF/com.x.utils:onComplete()[C:\Users\x\Adobe Flash Builder 4.6\whatever\src\com\x\utils\SWFLoader.as:77]
I searched on the internet to fix the security problem with allow domain, but it is still not working and I don't know what to do!
The crossdomain.xml file of content.mspcdns.com looks like this:
<?xml version="1.0"?>
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" secure="false"/>
<allow-http-request-headers-from domain="*" headers="*" secure="false"/>
</cross-domain-policy>
This is my current code (The error occurs at line 77 -> here after catch(error:Error) at onComplete(e:Event)):
public function loadSWF(param1: String):void {
var fullUrl:String = param1;
//fullUrl for example: https://content.mspcdns.com/swf/headwear/story_2022_girlhat_tk.swf
var loader:Loader = new Loader();
Security.allowDomain("*");
Security.allowInsecureDomain("*");
Security.allowDomain(loader.contentLoaderInfo.url);
Security.loadPolicyFile("https://content.mspcdns.com/crossdomain.xml");
var context: LoaderContext = new LoaderContext();
context.allowCodeImport = true;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
try {
loader.load(new URLRequest(fullUrl), context);
} catch(error:Error) {
ErrorHandler.triggerError("error", "Could not load SWF file!");
return;
}
function onComplete(e:Event):void {
var movie:MovieClip = new MovieClip();
try {
movie = e.currentTarget.content;
} catch(error:Error) {
//Convert it to Bitmap, when it can't be converted to MovieClip
var bitmapData:BitmapData = new BitmapData(e.currentTarget.content.width, e.currentTarget.content.height, true, 0x00000000);
bitmapData.draw(e.currentTarget.content);
var bitmap:Bitmap = new Bitmap(bitmapData);
//Add Bitmap to MovieClip
movie.addChild(bitmap);
}
movie.x = 25;
movie.y = 30;
stage.addChild(movie);
}
}
Maybe someone is experienced enough to help me out with this problem? Thank you
Upvotes: 1
Views: 127
Reputation: 181
I found a solution myself, but its probably not the best one and works only if the swf is run on the web:
Since the problem has been to access the swf from an external domain, I created a PHP script which will fetch the swf from the external domain and echo it. The PHP file is on the same server as the SWF file. The PHP script looks like this (q = the full url to the swf file):
<?php
header('Content-Type: application/x-shockwave-flash');
echo file_get_contents($_GET["q"]);
If someone has a better solution, please let me know!
Upvotes: 1