当从 CDN 提供服务时,预加载器如何动态确定目标 URL

发布于 2024-10-24 13:01:54 字数 714 浏览 7 评论 0原文

我有一个从 CDN 提供服务的预加载器,我希望它也从 CDN 加载目标 SWF,但是当它使用 loaderInfo 时,它会返回 html 文件的主机名...如下设置:

  • index.html(托管在主域上)使用 SWFObject 嵌入预加载器
  • preloader.as 托管在远程 CDN 上,包含
  • 要加载的 target.swf

下面的代码我从另一个我无法联系的开发人员那里继承了此代码,并且我不是 AS 编码员...

var url:String = "target.swf"; 
....
var request:URLRequest = new URLRequest(url);   
loader = new Loader();      
loader.load(request);   

这是我尝试过的,但我认为它返回的是 index.html 的 url,而不是 CDN 托管的预加载器:

var currentUrl:String = stage.loaderInfo.url; 
var url:String = currentUrl.substring(0,currentUrl.length-13) + "target.swf";
....

是否有某种方法可以获取预加载器是由哪个 CDN 提供的?

谢谢, 乔纳森

I have a preloader that is being served from a CDN, and I want it to load the target SWF also from the CDN but when it uses loaderInfo, it returns the hostname of the html file... Here's the setup:

  • index.html (hosted on primary domain) uses SWFObject to embed preloader
  • preloader.as hosted on remote CDN, contains code below
  • target.swf is to be loaded

I have inherited this code from another developer that I can't contact and I'm not an AS coder...

var url:String = "target.swf"; 
....
var request:URLRequest = new URLRequest(url);   
loader = new Loader();      
loader.load(request);   

This is what I've tried, but I think it's returning the url of the index.html, not the CDN-hosted preloader:

var currentUrl:String = stage.loaderInfo.url; 
var url:String = currentUrl.substring(0,currentUrl.length-13) + "target.swf";
....

Is there some way that I can get the URL that the preloader was served from which is the CDN?

Thanks,
Jonathan

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

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

发布评论

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

评论(1

悍妇囚夫 2024-10-31 13:01:54

stage.loaderInfo.url 实际上返回显示 swf 的页面的 URL。您可以将 CDN 的地址作为参数提供给您的 swf:

HTML

<script type="text/javascript">
    var flashvars = {CDNroot:'http://mycdn/'
    };
    var params = { 
        menu: "false",
        scale: "showAll",
        allowFullscreen: "true",
        allowScriptAccess: "always",
        quality:"best",
        bgcolor: "#FFFFFF"
    };
    var attributes = {
        id:"main", name:"main"
    };
    swfobject.embedSWF("loader.swf", "altContent", "100%", "100%", "10.0.0", "expressInstall.swf", flashvars, params, attributes);

</script>

然后要检索此参数,请使用:

AS3

var url:String = stage.loaderInfo.parameters["CDNroot"] + "target.swf";

stage.loaderInfo.url returns indeed the URL of the page displaying the swf. You may give your swf the address of the CDN as a parameter:

HTML

<script type="text/javascript">
    var flashvars = {CDNroot:'http://mycdn/'
    };
    var params = { 
        menu: "false",
        scale: "showAll",
        allowFullscreen: "true",
        allowScriptAccess: "always",
        quality:"best",
        bgcolor: "#FFFFFF"
    };
    var attributes = {
        id:"main", name:"main"
    };
    swfobject.embedSWF("loader.swf", "altContent", "100%", "100%", "10.0.0", "expressInstall.swf", flashvars, params, attributes);

</script>

Then to retrieve this parameter, use:

AS3

var url:String = stage.loaderInfo.parameters["CDNroot"] + "target.swf";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文