I was recently trying the URLRequest class in Actionscript 9 and hit this runtime error:
SecurityError: Error #2148: SWF file file:///C|/Documents%20and%20Settings/Lon/My%20Documents/Flash/Flash9/mxmlc/Loader/LoaderEx01.swf cannot access local resource file:///C|/Documents%20and%20Settings/Lon/My%20Documents/Flash/Flash9/mxmlc/Loader/PablumPicasso.jpg. Only local-with-filesystem and trusted local SWF files may access local resources. at flash.display::Loader/get content() at LoaderEx01/::imgLoaded()
The code example is was trying is:
package {
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
import flash.system.Security;
import flash.text.TextField;
public class LoaderEx01 extends Sprite {
//private var context:LoaderContext = new LoaderContext();
private var container:Sprite = new Sprite();
private var pictLdr:Loader = new Loader();
public function LoaderEx01()
{
var sandBoxType:String = String(Security.sandboxType);
var display_txt:TextField = new TextField();
display_txt.text = sandBoxType;
addChild(display_txt);
addChild(container);
var pictURL:String = "PablumPicasso.jpg"
var pictURLReq:URLRequest = new URLRequest(pictURL);
// To load swf locally and use Flex SDK 2binmxmlc add -use-network=false
// argument. The Flash 9 Alpha will allow swf to load locally and load image.
pictLdr.load(pictURLReq);
pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
}
private function imgLoaded(e:Event):void {
addChild(pictLdr.content);
}
}
}
I was using the Flex SDK 2 mxmlc compiler to create the swf file. Now it compiled perfectly. When I went to launch the swf from the local file server I got the security error message. However if I tried this in the Alpha version of the Flash 9 IDE it worked fine.
After a bit of research I found the option you need to set for mxmlc. It is -use-network=false. Once I added this switch to the command line the resulting swf could be loaded locally. I am using a Windows (DOS) batch file and so the resulting file appears as follows with the new switch:
"C:Program FilesAdobeFlex Builder 2Flex SDK 2binmxmlc" "-use-network=false" "C:Documents and SettingsLonMy DocumentsFlashFlash9mxmlcLoaderLoaderEx01.as"