In one of my recent projects, I had the requirement to open a browser window from within Flex on click of a button. Thats when I came across this Externalinterface call. Here is how I did it.
[xml]
private function openWindow():void
{
ExternalInterface.call("w_ = function () { window.win = window
.open(‘http://yahoo.com’,’TestPage’,’width=700,height=500′); }");
}[/xml]
Dont forget to do this though :-
[xml]
import flash.external.ExternalInterface;[/xml]
Might be useful to some of you trying to achieve the same in your project.
Thats actually nice trick. It will be much more useful for communicationg with JavaScript directly – you can do browser programming from inside Flex.
You can for example parse location, place divs, add or remove DOM nodes.
I think you just forgot to mention the most important part is this:
…call(“w_ = function() {…
as it triggers JS function execution. And you can’t place var before w_ at it will not work at all.
yes I agree to that. A whole lot of things can be done in terms of communicating with javascript and browser. placing a var before w_ will make it not work because then it will be treated as a flex variable? is that what you wanted to say?
No – I have no idea why it won’t work with var but it doesn’t 🙂
nice 🙂
I assume that FABridge will be popular once it’s outta beta status? This is something you would use with it, rather than ExternalInterface?
I havent got my hands dirty yet with the FABridge but from the looks of it, it looks like an interesting library. Thanks for letting me know, I am gonna try some of the examples out there.
Great! I’ll be awaiting your posts on it! I haven’t played with it much do to not developing in Flex yet, but from what I heard about it at MAX 2007… it sounded like it could be quite useful.
Sure Amy, I am gonna try it over the next couple days and will post it here once I do that.