Thursday, December 8th, 2005

E4X: Use it in Firefox, and anywhere Flash is installed?

Category: Editorial

Weiqi Gao talks about Native XML Comes To Firefox 1.5’s JavaScript.

I first blogged about E4X 425 days ago. At the time it was only available in Rhino. I’m happy to note that E4X support is part of JavaScript 1.6, which is delivered with Firefox 1.5.

Here is some of it in action:

<script type="application/x-javascript; version=1.5; e4x=1">
  var x = <div/>;
  x.@style = "margin-left:3em";
  x.span = "JavaScript for XML in Firefox 1.5"; 
  x.span.@style = "border: solid red 1pt";

What about using Flash?

However, I know a lot of you are crying “E4X is cool and all, but I can’t use it as IE and others don’t support it. So, who cares?”.

You may have a point, but how about this for craziness. Remember that Flash bridge (or three)? Remember that ActionScript in Flash supports E4X? Why not go ahead and use the bridge, pass over to it to have it do the E4X magic, and then get back over to the browser side? :)

Now we can use Flash for storage, for E4X, who cares about its graphic abilities! :)

Posted by Dion Almaer at 8:05 am

3.6 rating from 12 votes


Comments feed

uh.. no.

Flash 8.5, which is in *alpha* right now, supports E4X… but it doesn’t have anything to do with the browser’s DOM. Hardly anyone has this plugin installed unless they’re twiddling with ActionScript 3.0 or other 8.5 specific features.

If you were to try, you’d have to serialize the DOM to an XML string from JavaScript, get Flash to parse that, serialize to a string, and pass it back to JS to be parsed. That’s not very useful for most purposes, and is certainly a lot harder than just writing the equivalent E4X-free JavaScript.

Comment by Bob Ippolito — December 8, 2005

I don’t see E4X as an exciting enhancement anyway, the equivalent MochiKit.DOM expression to that example is actually one line:

appendChildNodes(document.body, DIV({style: “margin-left: 3em”}, SPAN({style: “border: solid red 1pt”}, “JavaScript for XML in Firefox 1.5”)));

I wish they’d have spent their spec-effort fixing some more important problems with JavaScript.

Comment by Bob Ippolito — December 8, 2005

You can’t actually use E4X in Flash for 2 reasons:

1) Flash Player 8.5 is still in alpha. Only a few developers are using it at the moment.

2) Flash only supports calling functions from JavaScript. You can’t really run E4X expressions in the transparent sort of way that would make it easy to code E4X without worrying about the browser. You’d still have to use a “if (MSIE) … ” kind of a check, which IMHO is not worth the trouble. Why not dump JavaScript and use Flash directly instead (when 8.5 is released)? ;)

Comment by Manish Jethani — December 8, 2005

[…] We talked before about Adobe’s Flash / JavaScript bridge. They’ve taken it to the next level with a new Flex / JavaScript bridge. Whereas the original integration kit allowed for invocation of ActionScript functions and passing simple primitive values, this new bridge enables seamless integration of Flex applications with the browser’s JavaScript environment. The Flex DOM and ActionScript environment can be completely manipulated from the JavaScript environment and vice versa, and complex types can be marshalled across seamlessly. So now Dion’s crazy post on using Flash’s E4X API to do JavaScript DOM just got a wee bit more practical. ;-) […]

Pingback by Ajaxian » Adobe Announces a Flex / Ajax Bridge — March 7, 2006

Leave a comment

You must be logged in to post a comment.