在 Actionscript / Flex 中将相对 URL 转换为绝对 URL

发布于 2024-08-16 23:54:49 字数 964 浏览 3 评论 0原文

我正在使用 Flex,我需要获取相对 URL 源属性并将其转换为绝对 URL,然后再加载。

我正在处理的具体案例涉及调整 SoundEffect 的加载方法。我需要通过查看源属性来确定文件是从本地文件系统加载还是通过网络加载,我发现最简单的方法是生成绝对 URL。

我在生成声音效果的绝对 URL 时遇到了问题。这是我最初的想法,但没有奏效。

  1. 查找声音效果所针对的 DisplayObject,并使用其 loaderInfo 属性。当 SoundEffect 加载时,目标为 null,因此这不起作用。

  2. 查看 FlexGlobals.topLevelApplication 的 url 或 loaderInfo 属性。然而,这些都没有设置。

  3. 查看 FlexGlobals.topLevelApplication.systemManager.loaderInfo。这也没有设置。

SoundEffect.as 代码基本上可以归结为

var url:String = "mySound.mp3";
/*>> I'd like to convert the URL to absolute form here and tweak it as necessary <<*/
var req:URLRequest = new URLRequest(url);
var loader:Loader = new Loader();
loader.load(req);

有人知道如何做到这一点吗?如果您能帮助澄清 ActionScript 中 URLRequest 的相对 url 解析规则,我们将不胜感激。

编辑 我也非常满意某种方式来判断 url 是从本地文件系统还是通过网络加载。查看绝对 URL 时,很容易查看前缀,例如 file://http://

I am working with Flex, and I need to take a relative URL source property and convert it to an absolute URL before loading it.

The specific case I am working with involves tweaking SoundEffect's load method. I need to determine if a file will be loaded from the local file system or over the network from looking at the source property, and the easiest way I've found to do this is to generate the absolute URL.

I'm having trouble generating the absolute URL for sound effect in particular. Here were my initial thoughts, which haven't worked.

  1. Look for the DisplayObject that the Sound Effect targets, and use its loaderInfo property. The target is null when the SoundEffect loads, so this doesn't work.

  2. Look at FlexGlobals.topLevelApplication, at the url or loaderInfo properties. Neither of these are set, however.

  3. Look at the FlexGlobals.topLevelApplication.systemManager.loaderInfo. This was also not set.

The SoundEffect.as code basically boils down to

var url:String = "mySound.mp3";
/*>> I'd like to convert the URL to absolute form here and tweak it as necessary <<*/
var req:URLRequest = new URLRequest(url);
var loader:Loader = new Loader();
loader.load(req);

Does anyone know how to do this? Any help clarifying the rules of how relative urls are resolved for URLRequests in ActionScript would also be much appreciated.

edit
I would also be perfectly satisfied with some way to tell whether the url will be loaded from the local file system or over the network. Looking at an absolute URL it would just be easy to look at the prefix, like file:// or http://.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月下凄凉 2024-08-23 23:54:49

我相信您只需将应用程序调用事件的 currentDirectory 属性放在 URL 的相对部分前面即可获取绝对 URL。请注意,其中仍可能包含 ./ 和 ../ 之类的内容。

以下是相关Adobe livedocs 页面:

var arguments:Array;
var currentDir:File;
public function onInvokeEvent(invocation:InvokeEvent):void {
    arguments = invocation.arguments;
    currentDir = invocation.currentDirectory;
}

I believe you just need to put the currentDirectory property of your application's invoke event in front of the relative part of your URL to get the absolute URL. Note that this could still contain things like ./ and ../ within it.

Here's some code from the relavant Adobe livedocs page:

var arguments:Array;
var currentDir:File;
public function onInvokeEvent(invocation:InvokeEvent):void {
    arguments = invocation.arguments;
    currentDir = invocation.currentDirectory;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文