Calling super()
on a function that you’ve overridden will simply also perform whatever code you have in the original function. For example:
/** Base function. */
public function traceStuff():void
{
trace("Hello!");
}
/** Overridden function in another class. */
override public function traceStuff():void
{
trace("Stuff");
super.traceStuff();
}
Having the super.traceStuff()
in the overridden function will still trace “Hello” as well as “Stuff” whenever you call the overridden function. However, if you remove the super.traceStuff()
, it only performs actions inside your overridden function and nothing from the base function, therefore only tracing “Stuff”. So really, it’s up to you whether or not you call super()
on functions or not.
Where you place the super()
depends on when you want the base function’s code called in relation to when your overridden function’s actions perform. So in the above example, trace("Hello")
would perform after trace("Stuff")
.
Keep in mind, some functions in FlashPunk actually require you to call super()
. For example, your World
update function will require the super.update()
so that the base World class actually gets updated, which in turn updates all your entities. Functions like added
and removed
will not require a super()
call because their original functions simply don’t contain any actions (unless of course you’ve added your own to them inside the FlashPunk source).