AS3 - 扩展功能?

发布于 2024-12-08 17:36:41 字数 168 浏览 1 评论 0原文

我有一个带有 destroy() 函数的实体类。

我还有一个扩展 Entity 的 Enemy 类,并且我想向 destroy() 函数添加一些行。

有没有办法扩展 ActionScript 3 中的功能,或者复制粘贴是可行的方法?谢谢。

I have an Entity class with a destroy() function.

I also have an Enemy class that extends Entity, and I want to add some lines to the destroy() function.

Is there a way to extend functions in ActionScript 3, or is copy and paste the way to go? Thanks.

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

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

发布评论

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

评论(1

合久必婚 2024-12-15 17:36:41

您需要使用 override 关键字标记该方法,并从那里使用相同的命名空间(publicprotected 等)和名称,使在要扩展的类中设置要重写的方法。

该方法还必须具有相同的返回类型并接受相同的参数

示例覆盖:

override public function destroy():void
{
    // add more code

    super.destroy();
}

如果排除读取 super.destroy() 的行,则基类中的函数将不会运行,并且只会使用您的新代码。

You need to mark the method with the override keyword, and from there use the same namespace (public, protected, etc) and name that make up the method you want to override in the class you're extending.

The method must also have the same return type and accept the same arguments

Sample override:

override public function destroy():void
{
    // add more code

    super.destroy();
}

If you exclude the line which reads super.destroy(), the function within the base class will not be run, and only your new code will be used instead.

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