在 ActionScript 3 中引发非自定义事件
我在 Flash Professional 中使用 ActionScript 3,我希望我的类引发一个事件,不是自定义事件,而是现有事件。我已经设置了我的类,以便它扩展 EventDispatcher。在文档中http://help.adobe。 com/en_US/FlashPlatform/reference/actionscript/3/flash/events/EventDispatcher.html 该示例通过添加静态字符串变量来声明自定义事件:
class CustomDispatcher extends EventDispatcher {
public static var ACTION:String = "action";
我假设启用:
Dispatcher.addEventListener(CustomDispatcher.ACTION, actionHandler);
或者至少在您在 Flash Professional IDE 中输入“dispatcher.addEventListener(”) 时自动完成。
但是很多类引发事件会引发现有非自定义事件的混合,例如,如果您有 flash.netFileReference 的实例并键入
。 fileRef.addEventListener(
给出了要侦听的一长串潜在事件,包括 DataEvent.UPLOAD_COMPLETE_DATA、Event.SELECT、HTTPStatusEvent.HTTP_STATUS、SecurityErrorEvent.SECURITY_ERROR 等。
如果我想要我的课程要注册以引发这些现有事件,我最好需要什么代码,以便 IDE 知道我的类的实例可以引发事件并在 addEventListener 中建议它们?自动完成/智能感知列表。
I'm using ActionScript 3 in Flash Professional and I'd like my class to raise an event, not a custom event but an existing one. I've set up my class so that it extends EventDispatcher. In the documentation http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/EventDispatcher.html the example declares a custom event by adding a static String variable:
class CustomDispatcher extends EventDispatcher {
public static var ACTION:String = "action";
I assume that enables:
dispatcher.addEventListener(CustomDispatcher.ACTION, actionHandler);
or at least auto-complete when you've typed 'dispatcher.addEventListener(' into the Flash Professional IDE.
But lots of classes that raise events raise a mixture of existing noncustom events. For example if you have an instance of a flash.netFileReference and type
fileRef.addEventListener(
a long list of potential events to listen for is given including DataEvent.UPLOAD_COMPLETE_DATA, Event.SELECT, HTTPStatusEvent.HTTP_STATUS, SecurityErrorEvent.SECURITY_ERROR, etc.
If I want my class to be registered to raise those existing events, what code do I need? Preferably so that the IDE knows instances of my class may raise the event and suggests them in the addEventListener auto-complete/intellisense list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

要使事件显示在智能感知中,您需要使用 事件元标记:
将其添加到调度此事件的类之前。
To make the events show up in the intellisense, you need to register them using the Event metatag:
Add this just before the classes that dispatches this event.