It's quite simple:
fTargetFile:File = File.applicationDirectory.resolvePath("assets");
fRootFile:File = File.applicationDirectory.resolvePath("assets");
fTargetFile.browseForOpen("test"); <-- here I open a file in "/assets/images/test.jpg"
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?
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:
var f1:File = (new File()).resolvePath(e.currentTarget.nativePath);
var f2:File = (new File()).resolvePath(File.applicationDirectory.nativePath);