So I’m sure this is probably at least mostly insane, but I was just thinking about AS3/JS interaction and it got me wondering – does anyone know exactly how inefficient calling JS via AS3 is? For example, if you do the following:
import flash.external.ExternalInterface;
ExternalInterface.call("(function() { /* here's a block of code */ })");
Do these calls need to be eval()ed in the end, or are they able to be passed natively?
Regardless: let’s be hypothetical for a second and say that you were a heretic and actually stored a good deal of Javascript within a utility SWF (1×1, offscreen, whatever), and had basic DOM events bound to hand those events to AS3 when they fire, which thus uses ExternalInterface to execute the JS immediately – thus the only part of your Javascript that is ever loaded is a little bit to communicate with Flash. A naive person might even say “you could condense numerous JS files into one loaded SWF file, separating them into different MC’s or whatever!”, but really, that’s not the point, and that won’t help us any after the page is already loaded.
I’ve used AS3 and its Socket class in lieu of XHR polling (etc), so I haven’t been disappointed with AS3/JS interaction so far. AFAIK AS3 is executed inside the Flash VM which means that it is automatically less efficient than Javascript, correct? Can someone shed some light on how terrible this would be, efficiency-wise?
It is not impossible to deconstruct the AS3 code within a Flash movie. While it would thwart the casual observer, if someone with skills wanted to get at your scripts they would be able to. You would only be throwing a roadblock in their path, not an impassable one, and possibly one that is even less difficult to crack than the code produced by standard JS obfuscators.
As for performance, Flash execution compares well with browser-hosted Javascript interpreters. See http://jacksondunstan.com/articles/232 for one set of comparisons. It is close to the fastest JS for sheer code execution*.
N.B. — And for graphical UI tasks nothing else (i.e., HTML 5) so far has even come close. This may change with IE9’s new JS engine and its hardware acceleration, but it is not clear whether Adobe will be able to tap into the same thing at some point.