2 Replies Latest reply on Jan 18, 2010 2:20 PM by masterkrang

    load local image display in air app

    masterkrang

      I am trying to load an image from the local file system, then diplay it in my air window. I don't have any problems getting the file reference from the open file dialog, problem is that I don't know what to do then. Somebody on another forum suggested using Loader.load to open the file using file.url as the URLRequest. This hasn't worked for me at all and I can't find any place online that explains how to do this. Thanks for the help

        • 1. Re: load local image display in air app
          Jeff Swartz Level 3

          Try this:

           

          var loader:Loader;

           

          var file:File = new File();
          var imagesFilter:FileFilter = new FileFilter("Images", "*.jpg;*.jpeg;*.gif;*.png");
          file.browseForOpen("Open file", [imagesFilter]);
          file.addEventListener(Event.SELECT, imgSelected);

           

          function imgSelected(event:Event):void
          {
              loader = new Loader();
              var urlReq:URLRequest = new URLRequest(file.url);
              loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
              loader.load(urlReq);
          }

           

          function imgLoaded(event:Event):void
          {
              var bmp:Bitmap = new Bitmap();
              bmp = loader.content as Bitmap;
              addChild(bmp);
          }

          • 2. Re: load local image display in air app
            masterkrang Level 1

            ok, i think i see where the mistake is.

             

            probably here: loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);

             

            i did this instead loader.addEventListener(Event.COMPLETE, imgLoaded);