Using the default html5 template, which fills the entire page, if the user resizes the browser window, this correctly resizes the stage, and Event.RESIZE is dispatched. So OpenFL definitely supports being resized dynamically after it has started.
Instead of resizing the Canvas, you might try resizing the <div> element that the Canvas is added to. In the default html5 template, it’s defined like this:
<div id="openfl-content"></div>
So you should be able to find it with something like document.getElementById("openfl-content") (if you’re using a custom template, it might have a different ID). Then, you can try resizing the <div> with something like div.style.width = "100px", and (hopefully) OpenFL can detect the change.
I ask other way.
I have universal graphics for my game wirt aspect ratio from 4:3 to 5:2. Game GUI is flexible. Game content is always centered - and black sides are appear for other aspect ratio. Example for AIR Windows version:
So I need the same for OpenFL project. But I even can’t recieve stage RESIZE event to implement it.
Is it possible?
Can your game fill the entire browser window? Or must it be a smaller region within the page?
Because the default settings for the html5 target are the fill the entire window, and the stage will automatically resize when the user resizes the window. So you should be able to use the exact same aspect ratio logic as in AIR.
However, when you set the window’s width/height in your project.xml, it forces the stage size to be a specific size with no resizing:
<window width="960" height="640"/> <!-- remove this -->
So to go back to the default behavior, just remove the part where you set the width and height.
Or, if you need to support other targets, you could do this instead: