I have a website on which I’m running a load.swf which loads a main.swf. I’m doing this so my users can see the download percentage. When I run the loader from Flashdevelop, it loads the .swf from my website (we’ll call it, www.mysite.com/games/main.swf), but when I run the loader.swf from the site itself, I get a security sandbox 2121 error… "ecurityError: Error #2121: Security sandbox violation: LoaderInfo.content: [URL=“http://www.mysite.com/loader.swf”]www.mysite.com/loader.swf cannot access [URL=“http://www.mysite.com/games/main.swf”]www.mysite.com/games/main.swf. This may be worked around by calling Security.allow"
Here’s my code for my loader.swf:
package
{
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.ProgressEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.system.Security;
import flash.system.SecurityDomain;
/**
- …
-
@author xxxxxxx
*/
public class Main extends Sprite
{
[Embed(source = “…/lib/title.png”)]
public var sharkTitle:Class;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
Security.allowDomain("");
Security.allowInsecureDomain("");
var sharkTitle:Bitmap = new sharkTitle();
sharkTitle.x = 250;
sharkTitle.y = 70;
sharkTitle.height = 150;
sharkTitle.width = 310;
var format:TextFormat = new TextFormat();
format.size = 50;
var percTxt:TextField = new TextField();
percTxt.width = 500;
percTxt.text = " ";
percTxt.setTextFormat(format);
percTxt.x = 300;
percTxt.y = 250;
addChild(sharkTitle);
addChild(percTxt);
function startLoad():void
{
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest(“www.mysite.com/games/main.swf”);
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
function onCompleteHandler(loadEvent:Event):void
{
addChild(loadEvent.currentTarget.content);
}
function onProgressHandler(mProgress: ProgressEvent):void
{
var percent:Number = mProgress.bytesLoaded / mProgress.bytesTotal;
percent = percent * 100;
Math.ceil(percent);
format.size = 50;
percTxt.setTextFormat(format);
percTxt.text = String(Math.ceil(percent)) + “% loaded”;
percTxt.setTextFormat(format);
if (percent > 99) { percTxt.visible = false;}
}
startLoad();
}
}
Thanks to any advice you can give…