Get full file path in AIR
1 Apr
Normally if you want a file path in Flex to upload a file you use FileReference() with a browse(). Last week I tried the same technique to get a file dragged from the desktop to my AIR application. After fixing a strange problem the code worked but the next problem appeared to me. With FileReference I only get the file name and I want the full path so save this to a SQLite database.
I searched quite some time to find the solution for this problem so I hope I save someone else his time with this explanation. In an AIR application you have an extra class called File. If you use this you get the full file path. Here is a little example code:
import mx.events.FileEvent; private var openFile:File = new File() private function openBrowseWindow():void{ openFile.addEventListener(Event.SELECT, onOpenFileComplete); openFile.browse(); } private function onOpenFileComplete(event:Event):void{ trace("event: "+event.target.nativePath); } |
Related posts:

Are you using it with AIR…because with Flex it doesn’t work..any idea?
Yeah this only work with AIR. In AIR the File class extends FileReference.
I used your code in my Flex-Application and had this errormessage: Type (File) was not found or was not a compile-time constant..
What should I do ?
You are missing the import of the File class
add this inside your script:
import flash.filesystem.File;Hi Arno,
What does this mean:
“I searched quite some time to find the solution for this problem so I hope I save someone else his time with this explanation. In an AIR application you have an extra class called File. If you use this you get the full file path. Here is a little example code:
d3d5df82dc545fb4ffbe77b1913c006a000″
Yeah I know that problem. On the front page of my blog you see a code example block but somehow it isn’t working in a single page view. Maybe I have to upgrade my wordpress but at this moment i have no time for that. In a few weeks I will try to fix it
I am not getting any class named File in flex3.
File is a AIR only class so If you start a new project you need to start an AIR project else you don’t have the File Class
Your using:
trace(“event: “+event.target.nativePath);
But you should use
trace(“event: “+event.target.url);
because nativePath works only on windows!
What is your source Michiel because on livedocs they don’t mention this restriction