The following source code shows three ways that how to load an image file.
- <?xml version=“1.0“ encoding=“utf-8“?>
- <mx:Application xmlns:mx=“http://www.adobe.com/2006/mxml“ layout=“absolute“ applicationComplete=“InitApp()“>
- <mx:Script>
- <![CDATA[
- //the first way:it will build “image.jpg” file into swf ( after building into swf,the image.jpg file is NOT needed)
- [Bindable]
- [Embed(source=“image.jpg“)]
- private var imgClass:Class;
- //the second way
- private var _loader:Loader;
- private function InitApp():void{
- // source code of the first way
- _img.source = imgClass;
- //source code of the second way
- _loader = new Loader();
- //notice: NOT _loader.addEventListener,is _loader.contentLoaderInfo.addEventListener
- _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void{
- _img.source = e.currentTarget.content;
- });
- _loader.load(new URLRequest(encodeURI(“image.jpg“)));
- //the third way
- _img.source = “image.jpg“; //Notice: set img autoLoad’s property to true
- //image.jpg file is needed by the second and the third way’s *.swf
- }
- ]]>
- </mx:Script>
- <mx:Image x=”51″ y=”62″ width=”298″ height=”245″ autoLoad=”true” id=”_img”/>
- </mx:Application>
Why do I get a security sandbox violation when trying to load an external image?
SecurityError: Error #2122: Security sandbox violation: LoaderInfo.content