修补 Flex 框架以立即显示预加载器?

发布于 2024-07-07 06:57:02 字数 417 浏览 7 评论 0原文

在 Flex 框架中,可以在加载站点时使用自定义预加载器。

Adobe 文档 中,它指定 ' 如果在下载 700 毫秒后下载的应用程序少于一半,则会显示进度条 [预加载器]。'

但是我总是希望预加载器立即出现,因为我知道我们 95% 的用户都在第一次访问者,该网站超过 500kb。 我不希望人们必须等待 0.7 秒才能出现预加载动画。

我认为理论上可以通过“猴子修补”框架来消除 0.7 秒的限制。 我没有时间弄清楚如何做,而且我以前从未这样做过。

有人帮忙吗?

In the Flex framework a custom preloader can be used while the site is loading.

In the Adobe docs it specifies that 'the progress bar [preloader] is displayed if less than half of the application is downloaded after 700 milliseconds of downloading.'

However I ALWAYS want the preloader to appear instantly since I know that 95% of our users are first time visitors and the site is over 500kb. I dont want people to have to wait .7 seconds for the preloader animation to appear.

I would think in theory that it is possible to 'monkey patch' the framework to remove this .7 second limitation. I dont have time to figure out how, and I've never done it before.

Anybody help?

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

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

发布评论

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

评论(4

小ぇ时光︴ 2024-07-14 06:57:02

您应该只扩展 DownloadProgressBar,尝试以下代码。 我以前用过这个,我找到了杰西·沃登网站 点击这里 usful 获取有关此内容的信息(我在那里找到了它,这是他的代码的精简版本)

package{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;

import mx.events.FlexEvent;
import mx.preloaders.DownloadProgressBar;

public class Preloader extends DownloadProgressBar
{

    /**
    * The Flash 8 MovieClip embedded as a Class.
    */      
    [Embed(source="yourPreloaderFile.swf")]
    private var FlashPreloaderSymbol:Class;

    private var clip:MovieClip;

    public function Preloader()
    {
        super();
        clip = new FlashPreloaderSymbol();
        addChild(clip);
    }

    public override function set preloader(preloader:Sprite):void 
    {                   
        preloader.addEventListener( FlexEvent.INIT_COMPLETE ,   onFlexInitComplete );

        centerPreloader();
    }

    private function centerPreloader():void
    {
        x = (stageWidth / 2) - (clip.width / 2);
        y = (stageHeight / 2) - (clip.height / 2);
    }

    private function onFlexInitComplete( event:FlexEvent ):void 
    {
        dispatchEvent( new Event( Event.COMPLETE ) ); 
    }


    protected override function showDisplayForDownloading(time : int, event : ProgressEvent) : Boolean {
        return true;
    }

}

}

之后只需更改 main 中的预加载器属性应用程序标记到 Preloader 类。

You should just extend the DownloadProgressBar, try the following code. i've used this before and I've found jesse warden site click here usful for info on this (where I found out about it and this is a cut down version of his code)

package{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;

import mx.events.FlexEvent;
import mx.preloaders.DownloadProgressBar;

public class Preloader extends DownloadProgressBar
{

    /**
    * The Flash 8 MovieClip embedded as a Class.
    */      
    [Embed(source="yourPreloaderFile.swf")]
    private var FlashPreloaderSymbol:Class;

    private var clip:MovieClip;

    public function Preloader()
    {
        super();
        clip = new FlashPreloaderSymbol();
        addChild(clip);
    }

    public override function set preloader(preloader:Sprite):void 
    {                   
        preloader.addEventListener( FlexEvent.INIT_COMPLETE ,   onFlexInitComplete );

        centerPreloader();
    }

    private function centerPreloader():void
    {
        x = (stageWidth / 2) - (clip.width / 2);
        y = (stageHeight / 2) - (clip.height / 2);
    }

    private function onFlexInitComplete( event:FlexEvent ):void 
    {
        dispatchEvent( new Event( Event.COMPLETE ) ); 
    }


    protected override function showDisplayForDownloading(time : int, event : ProgressEvent) : Boolean {
        return true;
    }

}

}

after that just change the preloader property in the main application tag to the Preloader class.

戒ㄋ 2024-07-14 06:57:02

这是 mx.preloaders::DownloadProgressBar.as 中 showDisplayForDownloading 函数的第 1205 行。

老派的猴子补丁已经在 AS3 中消失了,但是您可以编辑 Flex 源代码并自己编译一个新的 Framework.swc(显然很痛苦),或者只是将其包含在源路径中(源路径覆盖 .swcs); 或者从 DownloadProgressBar 派生您自己的预加载器类,该类仅覆盖 showDisplayForDownloading 并返回 true。

您可以在“%PROGRAMFILES%\Adobe\Flex Builder 3[ Plug-in]\sdks\3.0.0\frameworks\projects\framework\src”中找到框架源代码,然后是包路径。 如果您使用的是 3.1 或其他版本,请更改 sdk 版本。

This is in mx.preloaders::DownloadProgressBar.as, line 1205 in the showDisplayForDownloading function.

Old school monkey-patching is out with AS3, but you can either edit the Flex source and compile yourself a new framework.swc (apparently a pain), or just include it in your source path (source paths override .swcs); or derive your own preloader class from DownloadProgressBar that just overrides showDisplayForDownloading and returns true.

You can find the framework source in '%PROGRAMFILES%\Adobe\Flex Builder 3[ Plug-in]\sdks\3.0.0\frameworks\projects\framework\src', then the package path. Change the sdk version if you are using 3.1, or whatever.

蓝颜夕 2024-07-14 06:57:02

我猜延迟有两个原因:

  1. 你不希望预加载器
    一旦页面已经存在,就“闪烁”
    缓存
  2. 预加载器本身必须
    load

当我需要绝对确保立即显示预加载器时,我制作一个小型包装器 swf,其中预加载器并从那里加载主 swf。

I'd guess that delay is there for two reasons:

  1. You don't want the preloader to
    "blink" in once the page is already
    cached
  2. The preloader itself has to
    load

When I need to make absolutely sure a preloader is shown instantly I make a small wrapper swf that has just the preloader and load the main swf from there.

最偏执的依靠 2024-07-14 06:57:02

不可能立即显示预加载器,因为在显示进度之前需要下载一些类。 另一种选择是在 html 中显示进度,当加载 Flash 影片时,它会显示在此处。

its not possible to make preloader show instantly , since some classes needs to be downloaded before progress can be displayed . other alternative can be that you display a progress in html and when flash movie is loaded it shows up but here .

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