|
-
Anyone used FABridge? Feedback on new project.
Anyone used the FABridge? It's supposed to be a simple way of talking back and forth between flex and javascript. Looking at those docs, it doesn't seem all that simple.
I found it while doing some research for an idea I was working on this weekend, a more-or-less transparent actionscript/javascript interface. I've completed phase 1, which is getting javascript objects into actionscript in a way where they can be used without worrying that they are javascript objects. It's pretty neat.
You can literally do this in Actionscript:
Code:
var body:Object = LookingGlass.$('body'); //uses existing $ function on js side if there. In this case, jquery.
var htmlDoc:Object = LookingGlass.eval('document'); //can use eval directly
var newDiv:Object = htmlDoc.createElement("DIV"); //call javascript object methods
newDiv.innerHTML = "whoa."; //set/get javascript object properties
newDiv.id = "anewDiv";
body.append(newDiv);
You can even get access to javascript functions and call them natively in actionscript, or pass them as values.
I'm planning through phase 2, which is obviously actionscript objects in javascript, which is what FABridge is supposed to do. I'd like to make it as transparent as the above code.
I'll be writing this up on my blog tonight, but wanted to know whether anyone will find it useful, or had suggestions.
Should I embed the JS code in the actionscript package, or have it as a separate file? Should the package have the option to auto-inject jquery or some other framework? I'm not sure of the copyright implications of bundling jquery, but since it's MIT licensed it should be fine.
Anyway, please bombard me with your thoughts and criticisms.
-
Hot damn, that looks awesome!
I poked around in FABridge about a year ago - I don't recall exactly what was going on in there but at the time it seemed pretty inefficient and there wasn't anything there that you couldn't write for yourself (better).
It could be a good use for prototype-style monkey-patching so you don't have to go through a static class all the time...or maybe proxy the Object class?
-
You only need to go through the static class when you are getting something for the first time (not from another javascript object). In the code above, the static class is not referred to when calling methods or setting/getting properties (even though it is used in the background).
This already works by the magic of the Proxy class. The only things actually transferred are primitives (which are left unaltered) and small proxy-identification objects. Using Proxy's awesome callProperty, getProperty, setProperty, etc methods means that when a method like "createElement" is called, it simply goes to the javascript side, calls createElement on the original javascript object, and proxies the result to return to actionscript.
Functions are a bit more fiddly, but it's the same principle.
Oddly, it seems that javascript has proxy-ish methods for methods, but not for properties. I'll have to enumerate the properties explicitly, which means dynamic objects might be tricky.
Also, I haven't even tried this in IE yet. All my testing's been in Firefox. So far, It isn't anything weird, but the phase 2 stuff may not play well the way I was thinking of doing it.
-
I've written up phase 1 and made it available for download. http://cosmodro.me/blog/2009/mar/30/...glass-phase-1/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|