1 Reply Latest reply on Sep 30, 2010 9:18 PM by LLDLLDLLD

    encodeURI for file URI: Space Character in Filenames

    LLDLLDLLD

      Hi!

       

      I make use of the loader class to load images from the file system:

       

                    
                      loader.load(new URLRequest(encodeURI(f.url)));

       

      f is of type File and taken from a File.browseForOpen dialog.

       

      However, in case the filename of the selected file contains space characters, the statement above will not return any result - it just hangs...

       

      Is this by design? What is the best way to get around this?

       

      Best regards

       

      Roland

        • 1. Re: encodeURI for file URI: Space Character in Filenames
          LLDLLDLLD Level 1

          OK, I found a solution (link: http://techblog.floorplanner.com/2009/05/04/load-modify-and-save-local-images-with-flash-p layer-10/):

           

          It uses a FileReference, plus a Loader to load from the data member of the FileReference object. This way it also works with filenames containing space characters.

           

          HTH

           

          Roland

           

           

          private function loadFile():void {
                          loadFileRef = new FileReference();
                          loadFileRef.addEventListener(Event.SELECT, onFileSelect);
                          loadFileRef.browse();
                      }

           

          private function onFileSelect(e:Event):void {
                          loadFileRef.addEventListener(Event.COMPLETE, onFileLoadComplete);
                          loadFileRef.load();
                      }

           

          private function onFileLoadComplete(e:Event):void {
                             var loader:Loader = new Loader();
                             loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onDataLoadComplete);
                             loader.loadBytes(loadFileRef.data);

                          loadFileRef = null;
                      }

           

          private function onDataLoadComplete(e:Event):void {
                          var bitmapData:BitmapData = Bitmap(e.target.content).bitmapData;

                     .......

          ........

          ........