Flash build: openfl.display.Graphics does not have a constructor?

Is there some bug not allowing to build for Flash with openfl.display.Graphics?

class Main extends openfl.display.Sprite {
    public function new() {
        var g = new openfl.display.Graphics();

$ openfl test flash
Source/Main.hx:4: characters 10-39 : openfl.display.Graphics does not have a constructor

According to the documentation, trying to call new() on graphics should throw an exception so It’s not an bug (although I can’t tell the exact reason why it’s not possible). But in your example I can’t see any reason why you’d want to create a new graphics object since your sprite already has one automatically.

This is just simple example, it builds for every target except Flash. Indeed documentation states, that calling from ActionScript code throws an exception. I was fooled by “Available on all platforms” :wink:

As for real life usage - I am drawing to new Graphics so that I can do finally target_graphics.copyFrom(prepared_graphics), so its sort of “swap buffer” displayed on-demand.

For now i did work-around by creating Sprite not Graphics.

Yes, that is unfortunately true for a lot of things with openfl/haxe.

As another workaround you could maybe create an openfl.display.shape as a more lightweight alternative to a sprite.

Thanks for advice, I’ll use Shape indeed. :slight_smile:

Hopefully this will help: