在flex中监听来自预加载器的事件
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
预加载器的 INIT_COMPLETE 事件在预加载器收到应用程序的 CREATION_COMPLETE 事件后触发。
初始化的顺序是这样的:
在这种情况下,这意味着 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:
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.
预加载器将一直显示,直到您从预加载器调度 Event.COMPLETE 事件。
如果您想在预加载器完成和正在显示的应用程序之间显示某些内容,那么您需要在分派 Event.COMPLETE 之前在预加载器内执行此操作。 如果您不发送 COMPLETE 事件,您的预加载器将永远显示。
(如果您好奇,请查看“displayClassCompleteHandler”函数中的 Flex 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)
我不确定你到底想实现什么目标。 如果您只想在应用程序初始化或创建完成时执行某些操作,则可以在应用程序上使用creationComplete 或initialize 事件。 预加载器完成后您是否需要知道原因(假设这与应用程序中的creationComplete事件不同,我认为不会)?
更新:
所以您只是希望能够监听预加载器中的 Complete 事件,对吗?
试试这个:在应用程序上创建一个 initalize 事件处理程序,并尝试将一个事件侦听器附加到预加载器。 它看起来像这样(这没有经过测试,所以可能有拼写错误等)
看看是否可行。
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)
see if that could work.
当闪存应用程序完成初始化时,将触发 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.
在您的 Flex 应用程序中,您需要侦听 Application.applicationComplete 事件。
如果在您的 Preloader 类中,您有一个函数看起来像
您希望确保应用程序文件的标头看起来像
这样,则只要您决定从预加载器分派 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
you'll want to make sure the header to your Application file looks like
With this setup, onApplicationComplete() will get triggered whenever you decide to dispatch the Event.COMPLETE event from your preloader.
应用程序的 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?