AS3 [Event(name="", type="")],有什么意义?

发布于 2024-07-15 19:44:16 字数 525 浏览 5 评论 0 原文

我使用 FlashDevelop3 R2 和 Flex 3.3 SDK 进行开发,在很多情况下我必须使用嵌入元数据标签:

  [Embed(source="path/to/file")]
  private var Asset:Class;

我很好地理解上述所有内容,并且我很感激它的存在,因为我不喜欢打开 Flash IDE 太频繁了。

当我最近浏览其他作者的课程时,我发现了一个我不理解的有趣的元数据标签:

[Event(name="", type="")]

我还没有看到我需要这个的情况,而且我真的不明白它的用途。

预先感谢您的帮助。

布莱恩·霍奇
blog.hodgedev.com hodgedev.com

I develop with FlashDevelop3 R2 and the Flex 3.3 SDK and there are many occasions where I must use the embed metadata tag as such:

  [Embed(source="path/to/file")]
  private var Asset:Class;

I understand the above all well and good, and I am thankful it exists because I do not like to open the flash IDE too often.

When I am going through other authors classes lately, I have found an interesting metadata tag that I do not understand:

[Event(name="", type="")]

I have yet to see a situation where I require this, and furthermore I really just do not understand what it is for.

Thank in advance for your help.

Brian Hodge
blog.hodgedev.com hodgedev.com

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

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

发布评论

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

评论(2

尬尬 2024-07-22 19:44:16

这些[Event(name, type)]声明描述了类实例可能调度哪些事件。

它们实际上对于代码完成很有用 - 例如,当您键入:mySprite.addEventListener()时,您的代码编辑器(Flex Builder 或 FlashDevelop)将显示有意义的事件列表,这些事件 因此,您可以

在代码中添加这些声明,并从更丰富的代码完成中受益。

另请注意,这适用于自定义事件类(请参阅 FlashDevelop 的新事件类模板)。

package mycomp {
    import flash.events.Event;

    public class MyEvent extends Event {
         public const SOME_EVENT:String = "someEvent";
         // required Event type declarations
    }
}

package mycomp {
     [Event(name="someEvent", type="mycomp.MyEvent")]
     public class MyComp extends Sprite {
     }
}

package myproject {
     import mycomp.MyComp;

     public class MyProject {
          function MyProject() {
                var mc:MyComp = new MyComp();
                mc.addEventLister( //completes: SOME_EVENT + Sprite events
          }
     }
}

These [Event(name, type)] declarations describe which events a class instance is likely to dispatch.

They are actually useful for code completion - for instance when you type: mySprite.addEventListener(, your code editor (Flex Builder or FlashDevelop) will display a meaningful list of events that this object can dispatch.

So you can add these declarations in your code and benefit from a richer code completion.

Also note that this works with custom Event classes (see FlashDevelop's new Event class template).

package mycomp {
    import flash.events.Event;

    public class MyEvent extends Event {
         public const SOME_EVENT:String = "someEvent";
         // required Event type declarations
    }
}

package mycomp {
     [Event(name="someEvent", type="mycomp.MyEvent")]
     public class MyComp extends Sprite {
     }
}

package myproject {
     import mycomp.MyComp;

     public class MyProject {
          function MyProject() {
                var mc:MyComp = new MyComp();
                mc.addEventLister( //completes: SOME_EVENT + Sprite events
          }
     }
}
甜扑 2024-07-22 19:44:16

我们使用它来将自定义事件绑定到自定义 MXML 组件。 该标签允许您从 MXML 引用它。 请参阅文档

[事件(name="enableChanged", type="flash.events.Event")]

类 ModalText 扩展 TextArea {
<代码> ...
<代码>}

但是,如果您尝试引用未使用事件元标记声明的 mxml 标记上的事件,编译器会发出警告。

We use it for binding custom events to our custom MXML components. This tag allows you to reference it from MXML. See documentation:

[Event(name="enableChanged", type="flash.events.Event")]

class ModalText extends TextArea {
...
}

<MyComp:ModalText enableChanged="handleEnableChangeEvent(event);"/>

The compiler will complain, however, if you try to refer to an event on an mxml tag that was not declared with an event metatag.

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