Skip navigation
Currently Being Moderated

How to use getRelativePath() with browseForOpen()? It returns null

May 21, 2012 9:34 PM

It's quite simple:

 

fTargetFile:File = File.applicationDirectory.resolvePath("assets");

fRootFile:File = File.applicationDirectory.resolvePath("assets");

 

fTargetFile.addEventListener(Event.SELECT,onSelect)

fTargetFile.browseForOpen("test"); <-- here I open a file in "/assets/images/test.jpg"

 

function onSelect(e:Event):void

{

    trace(fRootFile.getRelativePath(fTargetFile));  <-- this returns null

}

 

Every single "tutorial" in the web - along with Adobe's documentation - gracefully uses resolvePath to explicitly point to the file objects, thereby bypassing the actual use case. getRelativePath indeed works with resolvePath, but using resolvePath means I've already known where the file is located in the first place, rendering getRelativePath actually useless

 

tracing the nativePath property of both objects returns the correct path.

 

 

What I'm trying to do is letting the user choose a file within the "assets" directory. The file can be from any folder so long as they're under the "assets", and once user chooses a file, display the relative path from "assets" to the chosen file.

 

So, in the example above, I expect "images/test.jpg" to be returned, but it returns nothing

 

Do I have to do some wizardry before getRelativePath works?

 
Replies
  • Currently Being Moderated
    Dec 20, 2012 5:54 AM   in reply to Raestloz

    This post is rather old, so I may not be able to help the original author of this topic, but as I found this thread, when searching for a solution for this problem myself, I might be able to help someone else.

     

    I found the following solution:

     

    function onSelect(e:Event):void

    {

      var f1:File = (new File()).resolvePath(e.currentTarget.nativePath);

      var f2:File = (new File()).resolvePath(File.applicationDirectory.nativePath);

      trace(f2.getRelativePath(f1, true));

    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points