apscience
apscience

Reputation: 7253

AS3 - extend a function?

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.

Upvotes: 3

Views: 4363

Answers (1)

Marty
Marty

Reputation: 39456

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.

Upvotes: 9

Related Questions