0

I'm working on an application and we are using Flash to add an interface. During the initialize the app loads in a config file with references to image paths. When I use the Loader and URLRequest classes to load those images the path is not working and it's causing issues. Based on everything I've researched my code should work. I have a trace that outputs "source/icons/default.png" which is the correct relative path for the external image and loading the image works, but I need to use a variable to set the image path. Setting the URLRequest with a variable, new URLRequest("source/icons/" + default.png);, causes it use a full file path that looks wrong and reports a 2035 error. Is there something that I'm doing wrong? I'm not sure what to do at this point. I've verified the file exists and I've verified the path of the file.

Trace Ouput: source/icons/default.png

Error Output:

[CompanionStatus] Error occurred while loading bitmap
[CompanionStatus] 2035 : Error #2035: URL Not Found. URL: file:///C|/Users/devtrooper/Desktop/project/source/icons/default.png

It looks like flash is replacing the colon (:) near the drive letter with a pipe (|) and I'm not sure if that is the issue.

Here is my method for loading images:

private function getBitmapData(nameString:String, imagePath:String):void{
    try{
        var bitmapDataFunction:Function = addBitmapDataToDictionary(nameString);
        var path:String = ICON_FOLDER_PATH + imagePath;
        var loader:Loader = new Loader();
        var urlRequest:URLRequest = new URLRequest("source/icons/" + imagePath);
        trace("URLRequest.url " + urlRequest.url);
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, bitmapDataFunction, false, 0, true);
        loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleBitmapDataError, false, 0, true);
        loader.load(urlRequest);
    } catch (e:Error) {
        log("Error occured while trying to load image data");
        log(e.name + " : " + e.message);
    }
}
  • The "C|..." is a correct output and shouldn't be a problem. Furthermore, there should be no difference between hard-coded URL and constructed URL, they're both **String**s. I'd start with char-to-char comparison between hardcoded one and constructed one, there **SHOULD** be something different. – Organis Nov 09 '20 at 07:16
  • IIRC you can't supply an URL with "file://C:" in it. You need to make your picture available at some other site, then supply the direct URL to there and also solve security issues that arise if your SWF is not published at the same site. – Vesper Nov 09 '20 at 09:50

1 Answers1

1

you can use File method instead of urlRequest method like this:

var urlPath:String="";
var picFile:File = File.desktopDirectory.resolvePath("source/icons/default.png");//you can use applicationDirectory,applicationStorageDirectory,userDirectory,doumenntDirectory and ... 
if (picFile.exists == true) { 
     urlPath = picFile.url;
}