立即显示 Flex 应用程序?

发布于 2024-09-16 09:13:18 字数 325 浏览 7 评论 0原文

我正在 Flex 中开发一个小项目,它是一个将图像上传到服务器的应用程序。由于它是一个非常轻量级的应用程序(发布版本约为 40 kb),我希望它能够在加载 html 页面时立即显示。但不知何故,在显示之前有长达 1-2 秒的延迟。我认为这实际上是应用程序的加载和显示之间的延迟,并且我相信它可以被删除。

但是,我找不到如何缩短/消除延迟的解决方案。首先,我尝试禁用预加载器,但这没有任何作用。实际上,预加载器关闭和应用程序显示之间存在延迟(大约 500 毫秒 - 1 秒)。我的下一个猜测是编写一个自定义预加载器类来至少显示应用程序的图像(即使它不可单击,但至少可以显示一些内容)。

任何建议将不胜感激。

I'm working on a little project in Flex that's an application to upload images to a server. Since it's a pretty lightweight application (~40 kb in release version), I would like it to display instantly when the html page is loaded. But somehow there's a delay of up to 1-2 seconds before it shows up. I think it is a delay actually between the load and the display of the application, and I believe it could be removed.

However, I couldn't find a solution on how to shorten/remove the delay. First, I tried to disable the preloader, but this did nothing. There's actually a delay between a preloader shuts and the application displays (it is around 500 ms - 1 sec). My next guess was to write a custom preloader class to display at least an image of the application (even though it wouldn't be clickable, but at least something).

Any advice would be greatly appreciated.

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

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

发布评论

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

评论(2

睫毛上残留的泪 2024-09-23 09:13:18

使用AS2,你会变得更简单和轻量级

尝试在as2中使用当前版本的swfloader

在flex4中使用它例如
合并到代码中,如下所示
http://devgirl.files.wordpress.com/2010/04/screen-shot-2010-04-07-at-2-26-32-pm.png

use AS2 instead, you'll get simpler and lightweight

try to use swfloader of current version in as2

use this in flex4 e.g.
Merged into code as here
http://devgirl.files.wordpress.com/2010/04/screen-shot-2010-04-07-at-2-26-32-pm.png

故事和酒 2024-09-23 09:13:18

好吧,我实际上设法获得了所需的行为。不过你的评论很有用。

方法如下。我为我的应用程序实现了一个自定义预加载器,并在预加载器的构造函数中加载了处于禁用状态的应用程序的图像(读取:屏幕截图)(以便用户不想与其交互)。我使用了此链接中的快照演示 - http://blogs.adobe.com /aharui/2010/01/custom_preloader_downloadprogr.html

这是我为预加载器编写的代码(大部分来自下面的链接,剪辑版本)


{

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import mx.events.FlexEvent;
import mx.events.RSLEvent;
import mx.preloaders.IPreloaderDisplay;

public class SSPreloader extends Sprite implements IPreloaderDisplay
{        
    [ Embed(source="startup.png", mimeType="application/octet-stream") ]
    public var WelcomeScreenGraphic:Class;

    private var loader:Loader;
    public function SSPreloader() 
    {
        super();

        loader = new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderBytesLoaded);
        loader.loadBytes(new WelcomeScreenGraphic() as ByteArray);
    }

    public function onLoaderBytesLoaded(event : Event) : void
    {
        loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoaderBytesLoaded);
        if (event.target.content != null)
        {
            var image:DisplayObject = event.target.content as DisplayObject; 
            addChildAt(image,0);
        }
    }


    private var _backgroundAlpha:Number = 1;
    public function get backgroundAlpha():Number
    {
        if (!isNaN(_backgroundAlpha))
            return _backgroundAlpha;
        else
            return 1;
    }

    public function set backgroundAlpha(value:Number):void
    {
        _backgroundAlpha = value;
    }

    //----------------------------------
    //  backgroundColor
    //----------------------------------

    private var _backgroundColor:uint;
    public function get backgroundColor():uint
    {
        return _backgroundColor;
    }
    public function set backgroundColor(value:uint):void
    {
        _backgroundColor = value;
    }

    //----------------------------------
    //  backgroundImage
    //----------------------------------

    private var _backgroundImage:Object;
    public function get backgroundImage():Object
    {
        return _backgroundImage;
    }
    public function set backgroundImage(value:Object):void
    {
        _backgroundImage = value;
    }

    //----------------------------------
    //  backgroundSize
    //----------------------------------

    private var _backgroundSize:String = "";
    public function get backgroundSize():String
    {
        return _backgroundSize;
    }
    public function set backgroundSize(value:String):void
    {
        _backgroundSize = value;
    }

    //----------------------------------
    //  preloader
    //----------------------------------

    private var _preloader:Sprite;         
    public function set preloader(value:Sprite):void
    {
        _preloader = value;

        value.addEventListener(ProgressEvent.PROGRESS, progressHandler);    
        value.addEventListener(Event.COMPLETE, completeHandler);

        value.addEventListener(RSLEvent.RSL_ERROR, rslErrorHandler);

        value.addEventListener(FlexEvent.INIT_PROGRESS, initProgressHandler);
        value.addEventListener(FlexEvent.INIT_COMPLETE, initCompleteHandler);
    }

    //----------------------------------
    //  stageHeight
    //----------------------------------

    private var _stageHeight:Number = 375;
    public function get stageHeight():Number 
    {
        return _stageHeight;
    }
    public function set stageHeight(value:Number):void 
    {
        _stageHeight = value;
    }

    //----------------------------------
    //  stageWidth
    //----------------------------------

    private var _stageWidth:Number = 500;
    public function get stageWidth():Number 
    {
        return _stageWidth;
    }
    public function set stageWidth(value:Number):void 
    {
        _stageWidth = value;
    }

    //--------------------------------------------------------------------------
    //
    //  Methods:IPreloaderDisplay
    //
    //--------------------------------------------------------------------------

    public function initialize():void
    {
    }

    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------

    private var lastBarWidth:Number = 0;
    protected function setDownloadProgress(completed:Number, total:Number):void
    {
    }

    protected function setInitProgress(completed:Number, total:Number):void
    {
    }

    protected function showDisplayForDownloading(elapsedTime:int,
                                                 event:ProgressEvent):Boolean
    {
        return false;
    }

    protected function showDisplayForInit(elapsedTime:int, count:int):Boolean
    {
        return false;
    }

    //--------------------------------------------------------------------------
    //
    //  Event handlers
    //
    //--------------------------------------------------------------------------

    protected function progressHandler(event:ProgressEvent):void
    {
    }

    protected function completeHandler(event:Event):void
    {
    }

    protected function rslErrorHandler(event:RSLEvent):void
    {
        _preloader.removeEventListener(ProgressEvent.PROGRESS,
            progressHandler);    

        _preloader.removeEventListener(Event.COMPLETE,
            completeHandler);

        _preloader.removeEventListener(RSLEvent.RSL_ERROR,
            rslErrorHandler);

        _preloader.removeEventListener(FlexEvent.INIT_PROGRESS,
            initProgressHandler);

        _preloader.removeEventListener(FlexEvent.INIT_COMPLETE,
            initCompleteHandler);
    }

    protected function initProgressHandler(event:Event):void
    {
    }

    protected function initCompleteHandler(event:Event):void
    {
        dispatchEvent(new Event(Event.COMPLETE)); 
    }
}    

}

我最终得到了一个很大的类,但它做了它应该做的事情。对代码的任何评论将不胜感激。

Well i actually managed to get the desired behavior. Your comments were useful though.

Here's how. I implemented a custom preloader for my application, and in the constructor of the preloader I loaded an image (read: screenshot) of my application in a disabled state (so that user won't want to interact with it). I used the SnapShot Demo from this link - http://blogs.adobe.com/aharui/2010/01/custom_preloader_downloadprogr.html

Here's the code that I wrote for the preloader (most of is is from the link below, a cut version):

package
{

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import mx.events.FlexEvent;
import mx.events.RSLEvent;
import mx.preloaders.IPreloaderDisplay;

public class SSPreloader extends Sprite implements IPreloaderDisplay
{        
    [ Embed(source="startup.png", mimeType="application/octet-stream") ]
    public var WelcomeScreenGraphic:Class;

    private var loader:Loader;
    public function SSPreloader() 
    {
        super();

        loader = new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderBytesLoaded);
        loader.loadBytes(new WelcomeScreenGraphic() as ByteArray);
    }

    public function onLoaderBytesLoaded(event : Event) : void
    {
        loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoaderBytesLoaded);
        if (event.target.content != null)
        {
            var image:DisplayObject = event.target.content as DisplayObject; 
            addChildAt(image,0);
        }
    }


    private var _backgroundAlpha:Number = 1;
    public function get backgroundAlpha():Number
    {
        if (!isNaN(_backgroundAlpha))
            return _backgroundAlpha;
        else
            return 1;
    }

    public function set backgroundAlpha(value:Number):void
    {
        _backgroundAlpha = value;
    }

    //----------------------------------
    //  backgroundColor
    //----------------------------------

    private var _backgroundColor:uint;
    public function get backgroundColor():uint
    {
        return _backgroundColor;
    }
    public function set backgroundColor(value:uint):void
    {
        _backgroundColor = value;
    }

    //----------------------------------
    //  backgroundImage
    //----------------------------------

    private var _backgroundImage:Object;
    public function get backgroundImage():Object
    {
        return _backgroundImage;
    }
    public function set backgroundImage(value:Object):void
    {
        _backgroundImage = value;
    }

    //----------------------------------
    //  backgroundSize
    //----------------------------------

    private var _backgroundSize:String = "";
    public function get backgroundSize():String
    {
        return _backgroundSize;
    }
    public function set backgroundSize(value:String):void
    {
        _backgroundSize = value;
    }

    //----------------------------------
    //  preloader
    //----------------------------------

    private var _preloader:Sprite;         
    public function set preloader(value:Sprite):void
    {
        _preloader = value;

        value.addEventListener(ProgressEvent.PROGRESS, progressHandler);    
        value.addEventListener(Event.COMPLETE, completeHandler);

        value.addEventListener(RSLEvent.RSL_ERROR, rslErrorHandler);

        value.addEventListener(FlexEvent.INIT_PROGRESS, initProgressHandler);
        value.addEventListener(FlexEvent.INIT_COMPLETE, initCompleteHandler);
    }

    //----------------------------------
    //  stageHeight
    //----------------------------------

    private var _stageHeight:Number = 375;
    public function get stageHeight():Number 
    {
        return _stageHeight;
    }
    public function set stageHeight(value:Number):void 
    {
        _stageHeight = value;
    }

    //----------------------------------
    //  stageWidth
    //----------------------------------

    private var _stageWidth:Number = 500;
    public function get stageWidth():Number 
    {
        return _stageWidth;
    }
    public function set stageWidth(value:Number):void 
    {
        _stageWidth = value;
    }

    //--------------------------------------------------------------------------
    //
    //  Methods:IPreloaderDisplay
    //
    //--------------------------------------------------------------------------

    public function initialize():void
    {
    }

    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------

    private var lastBarWidth:Number = 0;
    protected function setDownloadProgress(completed:Number, total:Number):void
    {
    }

    protected function setInitProgress(completed:Number, total:Number):void
    {
    }

    protected function showDisplayForDownloading(elapsedTime:int,
                                                 event:ProgressEvent):Boolean
    {
        return false;
    }

    protected function showDisplayForInit(elapsedTime:int, count:int):Boolean
    {
        return false;
    }

    //--------------------------------------------------------------------------
    //
    //  Event handlers
    //
    //--------------------------------------------------------------------------

    protected function progressHandler(event:ProgressEvent):void
    {
    }

    protected function completeHandler(event:Event):void
    {
    }

    protected function rslErrorHandler(event:RSLEvent):void
    {
        _preloader.removeEventListener(ProgressEvent.PROGRESS,
            progressHandler);    

        _preloader.removeEventListener(Event.COMPLETE,
            completeHandler);

        _preloader.removeEventListener(RSLEvent.RSL_ERROR,
            rslErrorHandler);

        _preloader.removeEventListener(FlexEvent.INIT_PROGRESS,
            initProgressHandler);

        _preloader.removeEventListener(FlexEvent.INIT_COMPLETE,
            initCompleteHandler);
    }

    protected function initProgressHandler(event:Event):void
    {
    }

    protected function initCompleteHandler(event:Event):void
    {
        dispatchEvent(new Event(Event.COMPLETE)); 
    }
}    

}

I got a huge class eventually, but it does what its supposed to. Any comments on the code would be appreciated.

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