On the mac, using "open" to run a swf has the disadvantage of obliterating the

current directory. The current directory is set to /.
So we can't read parameters.xml out of the current directory and we can't pass
the current directory in, because if we could do that we wouldn't need parameters.xml!
GAH! So read parameters.xml from the same directory as the SWF, because
that's the only thing we can reliably know about.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5133 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2008-05-25 03:16:56 +00:00
parent 9abef6df53
commit 821760366f
+20 -5
View File
@@ -30,6 +30,8 @@ import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.system.Capabilities;
/**
* A utility for loading parameters from an XML file when run from
* the local filesystem.
@@ -59,8 +61,10 @@ public class ParameterUtil
*/
public static function getInfoParameters (loaderInfo :LoaderInfo, callback :Function) :void
{
var url :String = loaderInfo.url;
// ensure that it's initialized...
if (loaderInfo.url == null) {
if (url == null) {
// Create a function to wait until the loaded object is initialized
var initWaiter :Function = function (event :Event) :void {
loaderInfo.removeEventListener(Event.INIT, initWaiter);
@@ -82,13 +86,24 @@ public class ParameterUtil
// Simply use the parameters in the loaderInfo if we were not
// loaded from a file.
if (0 != loaderInfo.url.indexOf("file:")) {
if (0 != url.indexOf("file:")) {
callback(loaderInfo.parameters);
return;
}
// else, let's try loading parameters.xml
// assume only windows uses the wrong slash
var fileSep :String = (-1 != Capabilities.os.indexOf("Windows")) ? "\\" : "/";
var dex :int = url.lastIndexOf(fileSep);
var paramUrl :String;
if (dex == -1) {
paramUrl = "file:";
} else {
paramUrl = url.substring(0, dex + 1);
}
paramUrl += "parameters.xml";
Log.getLog(ParameterUtil).info("Trying to load parameters from " + paramUrl);
// If we were loaded from a file, read our parameters from the
// parameters.xml file.
var loader :URLLoader = new URLLoader();
loader.addEventListener(IOErrorEvent.IO_ERROR,
function (event :Event) :void {
@@ -106,7 +121,7 @@ public class ParameterUtil
callback(params);
}
);
loader.load(new URLRequest("file:parameters.xml"));
loader.load(new URLRequest(paramUrl));
}
/**