Instant Flash player engine in JavaScript?

Note: This is not a posting about introducing Gordon. This article describes a concept of automatically porting the Flash Player to JavaScript in a generic way, based on the idea of Gordon and Adobe Alchemy.


You might know Gordon, an experimental attempt of implementing the Flash Player runtime environment, completely written in JavaScript (by Tobey Tailor).
Demos have already shown, that this is possible.

The idea itself is great: Create a Flash application as you’re used to and then compile it into a SWF file.
Then, embed it together with Gordon into your website like this:

<html>
	<head>
		<script type="text/javascript" src="/path/to/gordon.js"></script>
	</head>
	<body>
		<div id="your_stage">Replace me</div>
		<script type="text/javascript">
		var movie = new Gordon.Movie("/path/to/your.swf", {id: "your_stage", width: 480, height: 320});
		</script>
	</body>
</html>

The problem here is that I doubt that one person alone can completely re-implement the full Flash engine. This is somewhere close to impossible, since Gordon currently only supports SWF1, while the Flash Player was just released in version 10.1.
Even open-source projects like Gnash, a re-implementation of the Flash Player (written in C++), which already exists since several years, currently only support SWF7 and SWF8 partially.

Now, here comes my idea:

What, if it would be possible to automatically transform existing Flash Player implementations into JavaScript?

I know that this sounds crazy, but read the following first.

Ever heard of Alchemy? It’s a transformation tool, which converts C/C++ code into ActionScript and then build a Flash file from. Yes, you heard right. This is not an April joke. It’s real and it works. There have already been ports using the original (open) Quake2 source, transform it into ActionScript and then run the game inside Flash Player.

Now, since this is nothing new, here comes the big trick: Why not use the source code of Gnash, send it through Alchemy and achieve the ActionScript version of it.
Then, write a transformation tool, which converts ActionScript into JavaScript code. Since both languages share some syntax similarities, this should be possible (Especially if it is possible to transform C/C++ into ActionScript, which would sound even more crazy to me, if I’d hear it in the first place).
After this, the achieved JavaScript code must be cleared of anything that the Flash Player offers, but cannot be handled by JavaScript/HTML5, like for example web-cam support.
Finally, an interface must be written in order to output video and audio. Since HTML5 supports the new <canvas> and <audio> tags, this should be possible. Simply draw the content of the graphical buffer, generated by the Flash Player emulator, onto the canvas element and playback the sound using <audio>. Done.

This way, it would be possible to run (existing) Flash applications without having the Flash Player plugin installed.

I know, this still might sound crazy but it might be possible with enough man-power and the know-how. The only thing that might become a bigger problem is the file size. I wonder how big such a .js file, implementing the full(!) Flash Player, might become. Maybe it would then be necessary to package only required subsets of it.

So what do we get at the end? A JavaScript-version of the Flash Player which supports up to SWF8, thanks to Gnash.
If Adobe ever releases the Flash Player as open source, it would be easy to throw it into our C/C++-to-JavaScript transformator. Sounds great, or not?

Update: It just came to my mind that, if it’s possible to transform C/C++ into ActionScript, why shouldn’t be possible to directly cross-compile C/C++ into JavaScript?
As far as I know, Alchemy is based on LLVM, which should be able to handle this.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.