Resize stage manually?

In HTML5, the default created index.html file, prepared to resize the stage once the window has resized.
But I wonder, how would I invalidated the stage size manually? (I need to do so when Canvas size changes via code)

Please advice!

1 Like

I’ve been using this on openfl 3.6.1

public static function resizeCanvas(w:Int, h:Int, div:String = "openfl-content"):Void
{
        var canvas:Dynamic = untyped document.getElementById(div).childNodes[0];
        canvas.width = w;
        canvas.height = h;
        Lib.current.stage.window.resize(w, h);
        var html5Window:Dynamic = Reflect.getProperty(Lib.current.stage.window, "backend");
        Reflect.setField(html5Window, "setWidth", w);
	Reflect.setField(html5Window, "setHeight", h);
	Reflect.callMethod(html5Window, Reflect.field(html5Window, "handleResize"), []);
	Lib.current.stage.onWindowResize(Lib.current.stage.window, w, h);
}

There’s probably a better way to do this though :slight_smile:

1 Like

If you resize the parent DIV container, it should trigger a resize. If you call embed on a canvas element (instead of a DIV) it should trigger a resize if you resize the canvas element

Thanks, actually, I have fixed it by:

var evt = document.createEvent('UIEvents');
evt.initUIEvent('resize', true, false,window,0);
window.dispatchEvent(evt);