How to upload a background image using actionscript 3.0 code?

你。 提交于 2019-12-11 18:26:33

问题


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:


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);
}



回答2:


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.



来源:https://stackoverflow.com/questions/12104291/how-to-upload-a-background-image-using-actionscript-3-0-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!