jlehenbauer
jlehenbauer

Reputation: 599

Check if LOCAL file exists (Flex 4 Mobile)

I'm currently using this code:

        private function getFile(file:String):void
        {
            var openFile:URLRequest = new URLRequest("file:///sdcard/GNs/"+file);
            try {navigateToURL(openFile);}
            catch(e:Error)
            {
                var download:URLRequest = new URLRequest("http://"+file);
                new DLAlert().open(this, true);
            }
        }

to find a file, and give a popup for an optional download if it does not exist. The problem is, the errors returned when trying the navigateToURL(...) command are handled by the web/file browser, and not by the app. Is there a way to look for it without trying to open it?

Upvotes: 0

Views: 2137

Answers (1)

MAC
MAC

Reputation: 15847

Use this:

var myfile:File = new File("/sdcard/GNs/"+file);
if (myfile.exists)
{
   // your code here
}
else
{
   // your code here
}

Upvotes: 3

Related Questions