在flex中监听来自预加载器的事件

发布于 2024-07-16 08:06:42 字数 1038 浏览 9 评论 0原文

我的 Flex 应用程序中有一个预加载器:

public class Preloader extends DownloadProgressBar 
{

    private var _preloader:PreloaderAnimation;

    public function Preloader()
    {
        super();

        _preloader = new PreloaderAnimation;
        addChild(_preloader);
    }

    public override function set preloader(preloader:Sprite):void 
    {                   
        preloader.addEventListener(ProgressEvent.PROGRESS  , onSWFDownloadProgress );
        preloader.addEventListener(Event.COMPLETE          , onSWFDownloadComplete );
        preloader.addEventListener(FlexEvent.INIT_PROGRESS , onFlexInitProgress    );
        preloader.addEventListener(FlexEvent.INIT_COMPLETE , onFlexInitComplete    );
    }

    .........

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

当 Flex 初始化完成时,预加载器会调度一个 Event.COMPLETE。 但我希望能够在我的 Flex 应用程序中监听事件并在它调度时执行操作。 当它调度时,预加载器会自行删除,这就是它的重要性。 知道如何从我的 Flex 应用程序中收听吗?

问候阿德勒茨

I have a preloader in my flex application:

public class Preloader extends DownloadProgressBar 
{

    private var _preloader:PreloaderAnimation;

    public function Preloader()
    {
        super();

        _preloader = new PreloaderAnimation;
        addChild(_preloader);
    }

    public override function set preloader(preloader:Sprite):void 
    {                   
        preloader.addEventListener(ProgressEvent.PROGRESS  , onSWFDownloadProgress );
        preloader.addEventListener(Event.COMPLETE          , onSWFDownloadComplete );
        preloader.addEventListener(FlexEvent.INIT_PROGRESS , onFlexInitProgress    );
        preloader.addEventListener(FlexEvent.INIT_COMPLETE , onFlexInitComplete    );
    }

    .........

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

When the Flex Initialize is complete the preloader dispatches an Event.COMPLETE. But I want to be able to listen to the event in my flex app and do stuff when it dispatches. When it dispatches the preloader removes itself that's why its crucial. Any idea on how I could listen from my flex app?

Regards Adlertz

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

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

发布评论

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

评论(6

北城孤痞 2024-07-23 08:06:42

预加载器的 INIT_COMPLETE 事件在预加载器收到应用程序的 CREATION_COMPLETE 事件后触发。

初始化的顺序是这样的:

  • Preloader 开始加载你的应用程序;
  • 应用程序下载,开始初始化;
  • 应用程序初始化,调度 CREATION_COMPLETE;
  • 预加载器接收Application.CREATION_COMPLETE,调度INIT_COMPLETE;
  • 你的预加载器类接收预加载器的INIT_COMPLETE;
  • 您的预加载器调度 COMPLETE 事件;
  • 预加载器删除预加载器类并调度(私有)PRELOADER_DONE 事件;
  • 将显示您的应用程序。

在这种情况下,这意味着 Application.CREATION_COMPLETE 相当于 Preloader.INIT_COMPLETE - 如果您想知道预加载器何时调度 INIT_COMPLETE,则侦听 CREATION_COMPLETE。

您可以通过查看 Preloader 类的源代码来确认所有这些。

The Preloader's INIT_COMPLETE event is fired after the preloader receives the Application's CREATION_COMPLETE event.

The order of initialisation is this:

  • Preloader starts loading your app;
  • Application downloaded, starts initialising;
  • Application is initialised, dispatches CREATION_COMPLETE;
  • Preloader receives Application.CREATION_COMPLETE, dispatches INIT_COMPLETE;
  • Your preloader class receives the Preloader's INIT_COMPLETE;
  • Your preloader dispatches the COMPLETE event;
  • The Preloader removes your preloader class and dispatches the (private) PRELOADER_DONE event;
  • Your application is displayed.

What this means in this case is that the Application.CREATION_COMPLETE is equivalent to the Preloader.INIT_COMPLETE - if you want to know when the preloader dispatches INIT_COMPLETE then listen for CREATION_COMPLETE.

You can confirm all of this by looking through the source code for the Preloader class.

莳間冲淡了誓言ζ 2024-07-23 08:06:42

我需要知道预加载器何时完成的原因是因为我想在之后直接播放电影,其中电影中的第一帧看起来像预加载器的图像。

预加载器将一直显示,直到您从预加载器调度 Event.COMPLETE 事件。

如果您想在预加载器完成和正在显示的应用程序之间显示某些内容,那么您需要在分派 Event.COMPLETE 之前在预加载器内执行此操作。 如果您不发送 COMPLETE 事件,您的预加载器将永远显示。

(如果您好奇,请查看“displayClassCompleteHandler”函数中的 Flex Preloader 源代码)

The reason why I need to know when the preloader is complete is because I want to play a movie directly after, where the first frame in the movie looks like the image of the preloader.

The preloader is displayed until you dispatch the Event.COMPLETE event from your preloader.

If you want to display something between your preloader completing and the application being displayed then you would need to do it inside your preloader prior to dispatching Event.COMPLETE. If you do not dispatch the COMPLETE event your preloader will be displayed forever.

(If you're curious, look at the Flex Preloader source code in the 'displayClassCompleteHandler' function)

も让我眼熟你 2024-07-23 08:06:42

我不确定你到底想实现什么目标。 如果您只想在应用程序初始化或创建完成时执行某些操作,则可以在应用程序上使用creationComplete 或initialize 事件。 预加载器完成后您是否需要知道原因(假设这与应用程序中的creationComplete事件不同,我认为不会)?

更新:

所以您只是希望能够监听预加载器中的 Complete 事件,对吗?

试试这个:在应用程序上创建一个 initalize 事件处理程序,并尝试将一个事件侦听器附加到预加载器。 它看起来像这样(这没有经过测试,所以可能有拼写错误等)

public function applicationInitalize_handler ( e:FlexEvent ) : void
{
Application.preloader.addEventListener(Event.COMPLETE,myEventHandler);
}

看看是否可行。

I am not certain exactly what it is you are trying to achieve. If you are just wanting to do something at the time the application is initialized or creation is complete you can use the creationComplete or intialize events on the application. Is there a reason you need to know as soon as the preloader is complete (assuming that would be different than the creationComplete event from the application, I don't think it would be) ?

Update:

so you are just wanting to be able to listen to the Complete event from the preloader correct?

Try this: create an initalize event handler on the application and try to attach an event listener to the preloader. it would look something like this (this is not tested so it may have typos, etc)

public function applicationInitalize_handler ( e:FlexEvent ) : void
{
Application.preloader.addEventListener(Event.COMPLETE,myEventHandler);
}

see if that could work.

冬天的雪花 2024-07-23 08:06:42

当闪存应用程序完成初始化时,将触发 Flex.INIT_COMPLETE。 因此它是在主应用程序的初始化事件之后立即调度的。

Flex.INIT_COMPLETE is triggered when flash application has completed initialization. so its dispatched exactly after the initialize event of main applcation.

梦断已成空 2024-07-23 08:06:42

在您的 Flex 应用程序中,您需要侦听 Application.applicationComplete 事件。

如果在您的 Preloader 类中,您有一个函数看起来像

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

您希望确保应用程序文件的标头看起来像

<s:Application 
    preloader = "MyPreloader"
    applicationComplete="onApplicationComplete();" >

这样,则只要您决定从预加载器分派 Event.COMPLETE 事件,就会触发 onApplicationComplete() 。

In your Flex application, you need to listen for the Application.applicationComplete event.

If in your Preloader class you have a function that looks like

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

you'll want to make sure the header to your Application file looks like

<s:Application 
    preloader = "MyPreloader"
    applicationComplete="onApplicationComplete();" >

With this setup, onApplicationComplete() will get triggered whenever you decide to dispatch the Event.COMPLETE event from your preloader.

乱世争霸 2024-07-23 08:06:42

应用程序的 APPLICATION_COMPLETE 事件似乎是在预加载器触发 Event.COMPLETE 事件之后发出的……听听这个?

The application's APPLICATION_COMPLETE event seems to be issued just after the Preloader fires the Event.COMPLETE event... just listen to this?

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