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.
精彩评论