Adobe AIR file path on MAC and widows

2019-08-28 01:51发布

问题:

I have an Adobe Air application(based in flash) that loads in PNG files from a directory, there is a text file to specify the path, however it doesn't seem to be working on OSX while it works just fine on Windows

Windows path

C:\Users\User\Documents\Trees

This works just fine, however mac path

file:///Users/user/Desktop/trees/

or

Users/user/Desktop/trees/

Doesnt work, tried to reverse the slashed, didn't help either, anyone could help?

Update, heres the function that laods in the trees

private function LoadTrees():void
        {
            try
            {
                Trees = new Array();

                var currentDirectory:File = new File(currentPath);

                var files:Array = currentDirectory.getDirectoryListing(); 

                for (var i:int = 0; i < files.length; i++) 
                {
                    var fullFilePath:String = treePathLoader.data + "\\" + files[i].name;
                    var tree:Tree;

                    if (fullFilePath.indexOf(".png") > 0)
                    {
                        tree = new Tree(fullFilePath, treePositions.Tree[i].x, treePositions.Tree[i].y,treePositions.Tree[i].scale);
                        Trees.push(tree);
                    }
                }
            }
            catch(e:Error)
            {
                trace("ERROR");
            }
        }

回答1:

If you are not sure about the slash you can use File.separator. this example works fine for me:

"file://" + File.desktopDirectory.nativePath.toString() + File.separator + 'trees' + File.separator


回答2:

Did you try with /Users/user/Desktop/trees/? Or possibly ~/Desktop/trees/.