JSObject. It’s not just for Java anymore.

Back in the days, Netscape created this neat layer of glue called LiveConnect. Among other things, it would expose javascript objects to Java through a JSObject class.
Fast forward to ActionScript. ExternalInterface provides a way of eventually doing the same thing. Things like FABridge make things somewhat friendlier, but FABridge only deals with accessing ActionScript goodies from JavaScript.

So here’s JSObject. Yes, same name. In fact, it behaves remarkably similarly like its Java counterpart: Get a handle to the browser window, and climb up the DOM from there. However, it distinguishes itself by its transparent syntax.
To the untrained eye, it looks like your javascript objects have been carried over inside the Flash player.
For example, you can do this with it:

with (JSObject.getWindow()) {
e = document.getElementById(“test”);
b = document.createElement(“button”);
b.innerHTML = “Click me!”;
b.onclick = function(e:*):void {
alert(“clicked on “+this+” at “+e.clientX+“,”+e.clientY);

Except for the typing of the function parameter and return value, there is no difference between this and browser javascript code.
Even neater, if you put a breakpoint inside that code, you can browse through JSObject instances and effectively walk your browser DOM through the flash debugger.
There’s a lame demo that uses the above example.. You should probably browse the source view, though.
At the risk of giving away the ending, this is done by coupling flash.utils.Proxy with ExternalInterface, with a fair amount of javascript glue on the browser side.
It has various performance limitations, but hopefully that can be minimized over time.

Also, I’ve added another compiler to the as3 eval() project. This one is just a straight linkage of the ESC abc files, as made available through the tamarin-central repository. It works, but it’s not particularly more interesting than the AS3 version, for now. However, as time goes by, and the ESC stuff improves, it will be a cheap way to see those improvements in a pretty web UI, without some codemonkey having to port the darn thing over and over again.

Well that’s it for now. Eval and JSObject.. I wonder where I’m going with this.

Explore posts in the same categories: web, flash, actionscript, eval

2 Comments on “JSObject. It’s not just for Java anymore.”

  1. Vijay Chakravarthy Says:

    Hmm, Tamarin in Firefox before (tamarin inside firefox)..

    Very exciting. I was looking at your code (eval code), and am quite tempted to build a simple java class loader and executor in as3, which would do simple conversion of class files to as3 bytecode.

    This is really cool stuff (along with the TLS stuff as well) — love your work.

  2. Metal Hurlant Says:


    It would be very interesting to explore the possibilities of transcoding bytecodes between VMs, be it JVM, AVM2, CLR or LLVM..
    I suspect that in general it wouldn’t fit as a 1:1 mapping, and some layer of support would have to be added in the target VM to help emulate missing functionality from the source VM.
    That means you’d probably lose some runtime speed in the process.
    Still, there’d be value in working through it.