Why @:final for Graphics.hx?

I extended Sprite class and I want to call additional method when graphics.endFill() is called . As graphics is a part of Sprite , I want to override the method get_graphics() with my extended Graphics class where to replace endFill() with :``

    super.endFill();
    myMethodToCall(); 

but the Graphics class is final . Why is that ?
final seriously stop extending the class functionality .

Why I can’t tell you why it was made final, nothing is stopping you from either

  • removing the @:final metadata directly from Graphics.hx

  • make a duplicate of Graphics.hx inside your project’s source folder, which reflects the package’s location e.g. /openfl/display/Graphics.hx and remove the metadata tag there or modifiy it’s endFill() method

  • add the @:hack tag to the class which should extend Graphics e.g. @:hack class MyGraphics extends openfl.display.Graphics (though this option might cause trouble on some targets)

1 Like

In Flash, the flash.display.Graphics class is marked with the AS3 final keyword, so OpenFL also makes it final in Haxe. The Graphics class is not meant to be extended.

You might consider using Haxe static extensions instead.

2 Likes

Thanks to both of you for your reply and help