开发者

AS3 - extend a function?

开发者 https://www.devze.com 2023-04-11 02:47 出处:网络
I have an Entity class with a destroy() function. I also have an Enemy class that extends E开发者_StackOverflowntity, and I want to add some lines to the destroy() function.

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

I also have an Enemy class that extends E开发者_StackOverflowntity, 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消