Sometimes we need to load an image into our Flex application from URL,it’s very simple if the images are in a web-accessible directory.The below code is only a simple sample for it.You can modify it to suit your app.
PS.
While working on an AS 3 script I was getting an error like below(image):
Severity Description Resource In Folder Location Creation Time Id
2 Could not resolve <map:imgView> to a component implementation. imgView.mxml imgView 2008/02/10 1:17:08 26
I checked my action script file but there was no syntax error.Well was only because I forgot to create the “myLib” folder!
Download: imgView.as
- // ActionScript file (imgView.as)
- package myLib
- {
- import flash.display.Loader;
- import flash.events.Event;
- import flash.net.URLRequest;
- import mx.core.UIComponent;
- public class imgView extends UIComponent
- {
- private const image_path:String = “<a href=”http://blog.minidx.com/wp-content/uploads/2007/12/is.jpg”>http://blog.minidx.com/wp-content/uploads/2007/12/is.jpg”;</a>
- private var loader:Loader;
- private var request:URLRequest;
- public function imgView()
- {
- loader=new Loader();
- request=new URLRequest(image_path);
- loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
- loader.load(request);
- }
- private function onComplete(event:Event):void {
- addChild(loader);
- }
- }
- }
Download: imgView.mxml
- //mxml file(imgView.mxml):
- <?xml version=”1.0″ encoding=”utf-8″?>
- <mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” creationComplete=”onAppInit()” backgroundColor=”#3f3f3f” xmlns:map=”myLib.*”>
- <mx:Script>
- <![CDATA[
- public function onAppInit():void{
- Security.allowDomain(“http://blog.minidx.com/”);
- }
- ]]>
- </mx:Script>
- <map:imgView width =”100%” height=”100%” />
- </mx:Application>