Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 594
apscience Avatar asked May 19 '26 22:05

apscience


1 Answers

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.

like image 157
Marty Avatar answered May 22 '26 20:05

Marty