cca*_*dar 24

我们在这里要清楚.

1.如果需要加载的SWF文件的URL ,请使用其中一个.

在你的申请中:

this.url;
Run Code Online (Sandbox Code Playgroud)

从其他地方:

Application.application.url; // Flex 3
FlexGlobals.topLevelApplication.url; // Flex 4
Run Code Online (Sandbox Code Playgroud)

如果您在另一个SWF中加载SWF,请记住上面的代码将给出不同的值.this.url将返回SWF的url,其中Application.application.url将提供父/根SWF的url.

2.如果您想知道浏览器地址栏中的URL,请使用其中一个.

BrowserManager方法(确保您的包装器html中包含History.js以使其工作):

var browser:IBrowserManager = BrowserManager.getInstance(); 
browser.init();
var browserUrl:String = browser.url; // full url in the browser
var baseUrl:String = browser.base; // the portion of the url before the "#"
var fragment:String = browser.fragment; // the portion of the url after the "#"
Run Code Online (Sandbox Code Playgroud)

JavaScript方法:

var browserUrl:String = ExternalInterface.call("eval", "window.location.href");
Run Code Online (Sandbox Code Playgroud)

如果要解析参数的url,请不要忘记这个有用的函数:

// parses a query string like "key=value&another=true" into an object
var params:Object = URLUtil.stringToObject(browserURL, "&");
Run Code Online (Sandbox Code Playgroud)


jsi*_*ght 8

从应用程序:

var myUrl:String = Application.application.url;
Run Code Online (Sandbox Code Playgroud)


Koe*_*eyn 2

使用ExternalInterface ( flash.external.ExternalInterface),您可以在浏览器中执行Javascript。知道了这一点,你可以打电话

ExternalInterface.call("window.location.href.toString");

获取当前 URL(请注意,这将是页面 url,而不是 .swf url)。

科恩

  • 这不是**正确的答案,因为在大多数情况下,您不允许执行 JavaScript(例如:Kongregate 托管的 flash。) (2认同)