Flash and the JavaScript working directory
I use javascript to play a flash file, and it plays correctly. But it also needs to parse som开发者_开发技巧e configuration files in the flash default directory. So the problem is: the flash file I am going to play can't access its config file for the wrong working directory.
For example, I specify the swf path value as 'falsh/list/test.swf', so my javascript will give this swf value by swfobject.embedSWF
to play this flash. But the flash file flash/list/test.swf
needs to parse a config file in the same directory with flash file like flash/list/config.xml
. The problem is flash attempts to parse this config file under the current javascript working directory.
I've searched a lot, but haven't found a way to resolve this; can anyone help?
var name = parse_parameter('name');
var path = parse_parameter('path');
var swf = path+"/"+name+".swf";
swfobject.embedSWF(swf, "myContent", "800", "500", "9.0.0");
Your question is a bit vague, if you just want to find the working directory of the active thread you need to know a few things, namely a filename to look for. JS does not know where it comes from, however theres some tricks to finding a working directory. There's many implementations of this, I will copy what leaflet has done to find it's current directory.
https://github.com/CloudMade/Leaflet/blob/master/src/Leaflet.js
var scripts = document.getElementsByTagName('script');
for (var i = 0, len = scripts.length; i < len; i++) {
var src = scripts[i].src,
res = src && src.match(/^(.*\/)leaflet-*\w*\.js.*$/);
if (res && res[1]) { return res[1]; }
}
return '../../dist/';
The above looks for a script with name containing leaflet, then figures out the directory from the script src field.
Best of luck,
精彩评论