TeotiGraphix As I understand it, the Haxe compiler can generate JS code, and OpenFL implements a renderer that uses WebGL (OpenFL also has renderers that can use Canvas or the DOM instead). OpenFL is written in Haxe that gets compiled to JS, and it uses externs to access JS APIs, similarly to how Royale does the same.
There are compile-time conditionals in the OpenFL codebase that determine which renderer code paths are included in the output. So, it uses WebGL by default, but you can pass a flag to the Haxe compiler to make it use Canvas or DOM for rendering instead.
Obviously, there's some more involved when you consider that Haxe can generate c++ too. I think the basic architecture follows the same principles of using conditional compilation in OpenFL to activate the appropriate implementations for each platform, but I haven't gone that deep to understand it all completely.