在 Actionscript / Flex 中将相对 URL 转换为绝对 URL
我正在使用 Flex,我需要获取相对 URL 源属性并将其转换为绝对 URL,然后再加载。
我正在处理的具体案例涉及调整 SoundEffect 的加载方法。我需要通过查看源属性来确定文件是从本地文件系统加载还是通过网络加载,我发现最简单的方法是生成绝对 URL。
我在生成声音效果的绝对 URL 时遇到了问题。这是我最初的想法,但没有奏效。
查找声音效果所针对的 DisplayObject,并使用其 loaderInfo 属性。当 SoundEffect 加载时,目标为 null,因此这不起作用。
查看 FlexGlobals.topLevelApplication 的 url 或 loaderInfo 属性。然而,这些都没有设置。
查看 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.
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.
Look at FlexGlobals.topLevelApplication, at the url or loaderInfo properties. Neither of these are set, however.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您只需将应用程序调用事件的 currentDirectory 属性放在 URL 的相对部分前面即可获取绝对 URL。请注意,其中仍可能包含 ./ 和 ../ 之类的内容。
以下是相关Adobe livedocs 页面:
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: