0

Need your help. I am trying it first time.

I have used following code. But i get this in my console:

started loading file SecurityError: Error #2000: No active security context.

and my image url is in same folder as my script file.

var loader:Loader = new Loader();

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fileLoaded);
loader.load(new URLRequest("C:\Documents and Settings\Owner\Desktop\23Aug\demo1\mic.jpg"), context);
var context:LoaderContext = new LoaderContext();
context.applicationDomain = ApplicationDomain.currentDomain;
trace("started loading file");
addChild(loader);
function fileLoaded(event:Event):void
{
trace("file loaded");
}
  • 1
    You can't load a local file like that. Use a relative path, see if that fixes it. Also, you are not using your context for anything (nor should it be needed) – Jonatan Hedborg Aug 24 '12 at 07:09

2 Answers2

1

Reasons to throw securityError exception.

  • Invalid path,
  • Trying to access a URL, that not permitted by the security sandbox,
  • Trying a socket connection, that exceeding the port limit, and
  • Trying to access a device, that has been denied by the user(Ex., camera, microphone.)

try this

private var _loader:Loader = new Loader();
private var _context:LoaderContext = new LoaderContext();
private var _url:URLRequest = new URLRequest("demo1/mic.jpg");

_context.checkPolicyFile = false;
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageloaded);
//_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
_loader.load(_url, _context);
private function onImageloaded(e:Event):void{
    addChild(e.target.content);
}
Benny
  • 2,250
  • 4
  • 26
  • 39
0

Use slashes instead of back slashes :

loader.load(new URLRequest("C:/Documents and Settings/Owner/Desktop/23Aug/demo1\mic.jpg"), context);

But the best way is to use relative path like "./mic.jpg" and do not use absolute path.

Simon Eyraud
  • 2,445
  • 1
  • 20
  • 22