Thursday, September 10, 2009

Javascript injection from Flex into the HTML wrapper - problems with IE, of course

Here are some tips which might save someone some headaches (which you inevitably get when you start working with Internet Exploder).

First and foremost, if you want to communicate from Flex to (regular) Javascript using ExternalInterface in Internet Exploder (I was testing on version 6), you had better put an id attribute on the [object] and [embed] elements, or else it will either silently fail, or give you the wonderfully descriptive and logical error message 'null' is null or not an object. If I didn't know any better, I'd say it's rather philosophical. Oh, and it's always at character 118, line 1. I dare you to find it :)
You find this information if you read the first note on the Adobe documentation page for ExternalInterface.

When I said 'regular' earlier, I meant javascript that's already embedded in the page. Now, if you want to do nifty stuff like Javascript injection, you would probably use Abdul Qabiz's fantastic component. The reason I needed it was that our Flex application needed to be completely independent of the html wrapper it happened to find itself in, but also needed to open IFrames and move them around and do all kinds of nifty stuff (you can tell I like this word). That meant that the script would have to be embedded at runtime in the page by Flash.

Sounds doable, right? In Firefox, yes. In IE, haha, you've got another thing coming. IE and 'simplicity' have proven to be at opposite ends of the spectrum, time and time again.

I won't drone on about the specifics too much. But here are some major points to keep in mind:
For me the workaround didn't work yet... I'm trying to tweak it somehow to get it going. And it's great how you feel completely in the dark when it comes to these things, as the documentation seems to be lacking. It would have been great if IE6 had had the public bug tracking application IE7 and 8 do. But it would have probably crashed very early on, due to overuse.

No comments: