Posted by brandonthedeveloper at June 3rd, 2007

Here’s an Apollo gotcha I’ve been meaning to post for a few weeks now.

In a super secret app I am working on in Apollo, I need to allow the user to open files that have been saved to the App-Storage directory of the application. Sounds easy enough and it is easy enough but coming from a .net background I messed it all up.

You would think this would work but it doesn’t:
var file:File = File.appStorageDirectory.resolve(imageLib.selectedItem.name);
// pretend there is an image component on stage
myImage.source = file.nativePath;
// file.nativePath returns something like this on Windows:
C:\Documents and Settings\brandon\Application Data\MyApolloApp\Local Store\hungOverSanta.jpg
and this on Mac:
/Users/brandon/Library/Preferences/MyApolloApp/Local Store/hungOverSanta.jpg

both file paths are correct and if you plug them into an explorer window will pull up the image.

The correct way is like this:
var file:File = File.appStorageDirectory.resolve(imageLib.selectedItem.name);
// pretend there is an image component on stage
myImage.source = “app-storage:/” + file.name;

Huh?

I know there is some internal string association going on there but really, that is different than any type of File System Object I’ve ever seen. I only found one reply about it at the Adobe Forums. Hopefully my post here will save someone else the headache and (if I wasn’t bald already) hair pulling I went through while trying to figure this out.