Porting JS-Fireworks to Flash

Flash ActionScript is pretty much JavaScript right?
So, I thought my Chrome Experiment, js-fireworks should be trivial to port across to AS, and take advantage of the extra speed.
It did prove pretty simple.
Instead of a canvas, I create a Sprite. The Sprite has a graphics object which is usable in much the same way as the canvas. So all I needed to do was to switch the methods around a bit and voila!
One gotcha was the difference in calling setTimeout, which does not pick up the right context. When I call FireworkDisplay.blah, it should have the context of FireworkDisplay, not global.
Second gotcha was the redefinition of loop variables. This is illegal:

  
for (var i=0;i<20;i++) { } for (var i=0;i<20;i++) { }

I think this is a flaw in Flash. The var declares the loop counter to be local to the loop, so it should not "keep" a definition after exiting the loop. It's a pain.
Finally, the colours are a bit off. Don't know why - I pinched a simple util to convert rgb to hex, and I think it's off.
Anyway, it works. No extra speed though. Will have to look at optimization later.
Click here to see the demo.
Or click here to download the source.

Thanks for reading! I guess you could now share this post on TikTok or something. That'd be cool.
Or if you had any comments, you could find me on Twitter.

Published