预加载器挂起/冻结并伴有“打嗝”现象

发布于 2024-11-09 07:09:33 字数 4847 浏览 0 评论 0原文

我为拥有 GoDaddy 帐户并已将所有文件成功上传到托管服务器的客户开发了一个基于 Flash 的网站。该站点由一个名为“preloader.swf”的初始预加载器组成,它加载一个名为“main.swf”的外部 SWF 文件,该文件包含不同的部分,包括图像库部分。

然而,我注意到有时(并不总是发生这种情况)基于闪存的主站点的初始闪存预加载器加载速度比平时更快,但会出现“打嗝”。这导致当必须在站点的图库部分查看图像时(其中每个图像从具有自己的预加载器的服务器外部加载),所选图像以锯齿状方式加载,并带有“打嗝”(例如从22% 时暂停,然后立即跳至 31%,然后再次暂停并立即跳至 47%,依此类推)。

然后,在某个时间点,预加载器突然冻结/挂起整个站点,除了刷新站点别无选择。

只有这样,一旦图像的预加载器冻结并且刷新了站点,或者清除了缓存,整个站点才会像预想的那样完美工作 - 即初始预加载器加载得更慢、更流畅,并且当图像的预加载器加载时加载也更加平滑(百分比不会像以前那样突然跳跃;预加载器以正常增量加载)。

谁能告诉我可能的解决方案可能存在什么问题,如何使网站始终顺利加载,而不会遇到任何打嗝、冻结和挂起的情况,因为我一遍又一遍地检查我的代码,但我可以没发现有什么问题吗?

我正在做一些研究,发现原因可能是由于以下行“ProgressEvent.PROGRESS”,因为它有时可能不会在 IE 或 Firefox 中触发。是这样吗?如果是这样,我必须采取什么替代方案?

希望尽快听到答复。

谢谢&问候。

PS 下面我包含了用于加载主站点的初始预加载器的 AS 编码(不是用于加载图像的预加载器):

import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;

//no scale;
stage.scaleMode = StageScaleMode.NO_SCALE;

//align to top left
stage.align = StageAlign.TOP_LEFT;

stage.addEventListener(Event.RESIZE, onPreloaderResize);
addEventListener(Event.ENTER_FRAME, onPreloaderEnter);

angel_pic.alpha = 0;

top_left_line.visible = false;
top_right_line.visible = false;
side_left_line.visible = false;
side_right_line.visible = false;
bottom_left_line.visible = false;
bottom_right_line.visible = false;

var req:URLRequest = new URLRequest("main.swf");
var loader:Loader = new Loader();
loader.load(req);

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);

function showProgress(event:ProgressEvent):void
{
    var percent:Number = Math.round((event.bytesLoaded / event.bytesTotal) * 100);

    if ((percent > 0) && (percent <= 34))
    {
        top_left_line.visible = true;
        top_right_line.visible = true;

        top_left_line.width = percent * ((angel_pic.width / 2) / 34);
        top_right_line.width = percent * ((angel_pic.width / 2) / 34);
    }
    else
    {
        if ((percent > 34) && (percent <= 66))
        {
            side_left_line.visible = true;
            side_right_line.visible = true;

            side_left_line.height = (percent - 34) * (angel_pic.height / 32);
            side_right_line.height = (percent - 34) * (angel_pic.height / 32);
        }
        else
        {
            if (percent > 66)
            {
                bottom_left_line.visible = true;
                bottom_right_line.visible = true;

                bottom_left_line.width = (percent - 66) * ((angel_pic.width / 2) / 34);
                bottom_right_line.width = (percent - 66) * ((angel_pic.width / 2) / 34);
            }
        }
    }
}

function loadComplete(event:Event):void
{
    var num:int = numChildren;

    while (num--)
    {
        removeChildAt(num);
    }   

    addChild(loader);
}

function onPreloaderResize(event:Event):void
{
    var preloaderPadding:Number = (stage.stageWidth / 1000) * 35;

    angel_pic.x = (stage.stageWidth / 2) - (angel_pic.width / 2);
    angel_pic.y = (stage.stageHeight / 2) - (angel_pic.height / 2);

    angel_pic.width = stage.stageWidth - (preloaderPadding * 2);
    angel_pic.height = angel_pic.width / 4.9;

    top_left_line.x = stage.stageWidth / 2;
    top_left_line.y = angel_pic.y;

    top_right_line.x = stage.stageWidth / 2;
    top_right_line.y = angel_pic.y;

    side_left_line.x = preloaderPadding + side_left_line.width;
    side_left_line.y = angel_pic.y;

    side_right_line.x = preloaderPadding + angel_pic.width;
    side_right_line.y = angel_pic.y;

    bottom_left_line.x = preloaderPadding + bottom_left_line.height;
    bottom_left_line.y = angel_pic.y + angel_pic.height;

    bottom_right_line.x = preloaderPadding + angel_pic.width;
    bottom_right_line.y = angel_pic.y + angel_pic.height;
}

function onPreloaderEnter(event:Event):void
{
    var preloaderPadding:Number = (stage.stageWidth / 1000) * 35;

    angel_pic.x = (stage.stageWidth / 2) - (angel_pic.width / 2);
    angel_pic.y = (stage.stageHeight / 2) - (angel_pic.height / 2);

    angel_pic.width = stage.stageWidth - (preloaderPadding * 2);
    angel_pic.height = angel_pic.width / 4.9;

    top_left_line.x = stage.stageWidth / 2;
    top_left_line.y = angel_pic.y;

    top_right_line.x = stage.stageWidth / 2;
    top_right_line.y = angel_pic.y;

    side_left_line.x = preloaderPadding + side_left_line.width;
    side_left_line.y = angel_pic.y;

    side_right_line.x = preloaderPadding + angel_pic.width;
    side_right_line.y = angel_pic.y;

    bottom_left_line.x = preloaderPadding + bottom_left_line.height;
    bottom_left_line.y = angel_pic.y + angel_pic.height;

    bottom_right_line.x = preloaderPadding + angel_pic.width;
    bottom_right_line.y = angel_pic.y + angel_pic.height;
}

I've developed a flash-based site for a client who has an account with GoDaddy and have uploaded all files successfully to the hosting server. The site consists of an initial preloader named “preloader.swf”, which loads an external SWF file named “main.swf” that contains different sections including an image-gallery section.

However, I notice that at times (as not always this happens) the initial flash preloader for the main flash-based site loads faster than usual with "hiccups". This results in when having to view an image in the gallery section of the site (where each image is loaded externally from the server having a preloader of its own), the selected image loads in a jagged manner with "hiccups" (for instance from 22% it pauses then jumps immediately to 31%, then pauses again and jumps immediately to 47%, and so on).

Then, at a point in time, the preloader suddenly freezes/hangs the entire site, having no other choice but to refresh the site.

Only then, once the preloader of the image has froze and the site is refreshed, or the cache is cleared, will the entire site work perfectly as supposed to - i.e. the initial preloader loads more slower and smoother, and the preloaders of when the images are loading are more smoother as well (no sudden jumps in the percentages as before; the preloader loads in normal increments).

Could anyone please tell me what the problem might be with a possible solution in how I can make the site load smoothly always without having to encounter any hiccups, freezing and hanging, as I've been checking my code over and over again but I can't find anything wrong with it?

I was doing some research and read that the cause might be because of the following line "ProgressEvent.PROGRESS" as it might not fire at times in IE or Firefox. Is that so? If so, what alternative must I take?

Hope to be hearing a reply as soon as possible.

Thanks & Regards.

P.S. Below I have included the AS coding for my initial preloader to load the main site (not the preloader used to load images):

import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.ProgressEvent;

//no scale;
stage.scaleMode = StageScaleMode.NO_SCALE;

//align to top left
stage.align = StageAlign.TOP_LEFT;

stage.addEventListener(Event.RESIZE, onPreloaderResize);
addEventListener(Event.ENTER_FRAME, onPreloaderEnter);

angel_pic.alpha = 0;

top_left_line.visible = false;
top_right_line.visible = false;
side_left_line.visible = false;
side_right_line.visible = false;
bottom_left_line.visible = false;
bottom_right_line.visible = false;

var req:URLRequest = new URLRequest("main.swf");
var loader:Loader = new Loader();
loader.load(req);

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);

function showProgress(event:ProgressEvent):void
{
    var percent:Number = Math.round((event.bytesLoaded / event.bytesTotal) * 100);

    if ((percent > 0) && (percent <= 34))
    {
        top_left_line.visible = true;
        top_right_line.visible = true;

        top_left_line.width = percent * ((angel_pic.width / 2) / 34);
        top_right_line.width = percent * ((angel_pic.width / 2) / 34);
    }
    else
    {
        if ((percent > 34) && (percent <= 66))
        {
            side_left_line.visible = true;
            side_right_line.visible = true;

            side_left_line.height = (percent - 34) * (angel_pic.height / 32);
            side_right_line.height = (percent - 34) * (angel_pic.height / 32);
        }
        else
        {
            if (percent > 66)
            {
                bottom_left_line.visible = true;
                bottom_right_line.visible = true;

                bottom_left_line.width = (percent - 66) * ((angel_pic.width / 2) / 34);
                bottom_right_line.width = (percent - 66) * ((angel_pic.width / 2) / 34);
            }
        }
    }
}

function loadComplete(event:Event):void
{
    var num:int = numChildren;

    while (num--)
    {
        removeChildAt(num);
    }   

    addChild(loader);
}

function onPreloaderResize(event:Event):void
{
    var preloaderPadding:Number = (stage.stageWidth / 1000) * 35;

    angel_pic.x = (stage.stageWidth / 2) - (angel_pic.width / 2);
    angel_pic.y = (stage.stageHeight / 2) - (angel_pic.height / 2);

    angel_pic.width = stage.stageWidth - (preloaderPadding * 2);
    angel_pic.height = angel_pic.width / 4.9;

    top_left_line.x = stage.stageWidth / 2;
    top_left_line.y = angel_pic.y;

    top_right_line.x = stage.stageWidth / 2;
    top_right_line.y = angel_pic.y;

    side_left_line.x = preloaderPadding + side_left_line.width;
    side_left_line.y = angel_pic.y;

    side_right_line.x = preloaderPadding + angel_pic.width;
    side_right_line.y = angel_pic.y;

    bottom_left_line.x = preloaderPadding + bottom_left_line.height;
    bottom_left_line.y = angel_pic.y + angel_pic.height;

    bottom_right_line.x = preloaderPadding + angel_pic.width;
    bottom_right_line.y = angel_pic.y + angel_pic.height;
}

function onPreloaderEnter(event:Event):void
{
    var preloaderPadding:Number = (stage.stageWidth / 1000) * 35;

    angel_pic.x = (stage.stageWidth / 2) - (angel_pic.width / 2);
    angel_pic.y = (stage.stageHeight / 2) - (angel_pic.height / 2);

    angel_pic.width = stage.stageWidth - (preloaderPadding * 2);
    angel_pic.height = angel_pic.width / 4.9;

    top_left_line.x = stage.stageWidth / 2;
    top_left_line.y = angel_pic.y;

    top_right_line.x = stage.stageWidth / 2;
    top_right_line.y = angel_pic.y;

    side_left_line.x = preloaderPadding + side_left_line.width;
    side_left_line.y = angel_pic.y;

    side_right_line.x = preloaderPadding + angel_pic.width;
    side_right_line.y = angel_pic.y;

    bottom_left_line.x = preloaderPadding + bottom_left_line.height;
    bottom_left_line.y = angel_pic.y + angel_pic.height;

    bottom_right_line.x = preloaderPadding + angel_pic.width;
    bottom_right_line.y = angel_pic.y + angel_pic.height;
}

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

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

发布评论

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

评论(2

被翻牌 2024-11-16 07:09:33

我以前也遇到过预加载器问题。

尽管您的代码中仍然可能存在问题,但您可能希望排除另一个已知问题作为问题根源。

如果您仅在生产服务器上遇到问题,而不是在本地电脑上遇到问题,则很有可能您的服务器设置可能是罪魁祸首。

查看我的博文,了解压缩二进制文件的服务器 gzip 压缩。
虽然这是一篇关于 Flex 的文章,但原理是相同的,也应该适用于 Flash。

干杯

I have experienced preloader problems as well before.

Though it still might be something wrong in your code, there might be another known issue you might want to exclude as the source of your problem.

If you experience the problem only on your production server and not locally on your pc, there is a good chance that your server setup might be the culprit.

Check my blogpost about server gzip compression of compressed binary files.
Though it is a post about flex, the principle is the same and should apply to flash as well.

Cheers

留一抹残留的笑 2024-11-16 07:09:33

在将网站上传到 GoDaddy 服务器之前,我曾经使用 Flash 自己的“模拟下载”选项对其进行测试,但从未遇到过任何问题。

直到我上传网站后,我才开始遇到这个问题。

我无法理解和解决的奇怪的事情是,只有当预加载器冻结/挂起并且刷新站点或清除缓存时,整个站点才会像预期的那样完美工作,没有任何故障或锁定- UPS!

我什至上传了一个更简单版本的预加载器(如下面的代码所示),该预加载器加载了一个包含单张图片的 3Mb SWF 文件,但仍然再次出现相同的问题。但我不认为代码有问题,对吗?

var req:URLRequest = new URLRequest("main-mini.swf");
var loader:Loader = new Loader();
loader.load(req);

loader.contentLoaderInfo.addEventListener(Event.OPEN, showPreloader);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, showContent);

var preloader:Preloader = new Preloader();

function showPreloader(event:Event):void {
    addChild(preloader);
    preloader.x = (stage.stageWidth / 2) - (preloader.width / 2);
    preloader.y = (stage.stageHeight / 2) - (preloader.height / 2);
}

function showProgress(event:ProgressEvent):void {
    var percent:Number = event.bytesLoaded / event.bytesTotal;
    preloader.percentage.text = Math.round(percent * 100) + "%";
    preloader.bar.width = 300 * percent;
}

function showContent(event:Event):void {
    removeChild(preloader);
    addChild(loader);
}

我还尝试在 HTML 和 Flash 中使用缓存清除技术,并将其帧速率从 31fps 降低到 21fps,但一切都是徒劳。

我可能会问一些愚蠢的问题,但这可能是来自 GoDaddy 服务器的问题吗?我是否应该调整一些设置才能使其正常工作,或者我可能“错误”地上传了它?我使用 FTP 方法通过 Dreamweaver 上传该网站。我不知道此时该想到什么...

如果有人能够启发我如何解决我的这个问题,我将非常感激,因为一切都在本地正常工作 - 一旦上传,问题就解决了呈现自己。

谢谢。

Before uploading the site to the GoDaddy server, I used to test it using Flash's own "Simulate Download" option and never had I experienced any problem whatsoever.

Only once I uploaded the site, I started experiencing this problem.

The strange thing that I can't manage to understand and solve is that only when the preloader has froze/hung and the site is refreshed, or the cache is cleared, will the entire site work perfectly as supposed to with no glitches or lock-ups!

I even uploaded a simpler version of the preloader (as shown in the code below) that loads a 3Mb SWF file containing a single picture in it, and still the same problem is present once again. But I don't think there is a problem in the code, am I right?

var req:URLRequest = new URLRequest("main-mini.swf");
var loader:Loader = new Loader();
loader.load(req);

loader.contentLoaderInfo.addEventListener(Event.OPEN, showPreloader);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, showContent);

var preloader:Preloader = new Preloader();

function showPreloader(event:Event):void {
    addChild(preloader);
    preloader.x = (stage.stageWidth / 2) - (preloader.width / 2);
    preloader.y = (stage.stageHeight / 2) - (preloader.height / 2);
}

function showProgress(event:ProgressEvent):void {
    var percent:Number = event.bytesLoaded / event.bytesTotal;
    preloader.percentage.text = Math.round(percent * 100) + "%";
    preloader.bar.width = 300 * percent;
}

function showContent(event:Event):void {
    removeChild(preloader);
    addChild(loader);
}

I tried also using a cache-busting technique in both the HTML and Flash, and reducing its frame rate from 31fps to 21fps but all was for nothing.

I might be asking something stupid, but could it be something from the GoDaddy server? Could there be some setting I should adjust for it to work properly or maybe I could have uploaded it "badly"? I uploaded the site through Dreamweaver using the FTP method. I don't know what to think of at this point...

If anyone could enlighten me as to how I may solve this problem of mine, I would be tremendously grateful, because all works fine locally - once it is uploaded, the problem presents itself.

Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文