May 20 2008
Allowing Popups to work
In AS 2.0 or earlier when you use getURL to open up a new browser window, usually it wouldn’t get blocked by popups if the getURL call was made onRelease event instead of onPress. But with navigateToURL introduced in AS 3.0 its a different story altogether.
navigateToURL works fine with Safari but doesn’t work in Firefox (I am a mac user so i personally test in these two browsers). Anyway to make sure that popups open we have to use some javascript and call it from our Flash.
Adobe recommends we use ExternalInterface since the 9.0.124 update. So here is my Flash code,
if (boolean == "false"){
navigateToURL(new URLRequest(url),"_blank");
}
and my Javascript would look something like this,
var winName = Math.round(9999*Math.random()) + new Date().getTime();
var winNew = window.open(pageUrl,winName,"toolbar=1,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=800,height=700,left=200,top=100");
if(!winNew) {
return "false";
} else {
return "true";
}
}
So with this method we first try to open a window using Javascript, Firefox is happy with that and hence it returns true and flash doesn’t make a call to navigateToUrl. Safari blocks the javascript popup and hence true is returned to Flash and using navigateToUrl you can open up a new browser window.
It seems to work with IE as well otherwise i would have got a bug reported from the QA team.
I keep getting a “null” error when I try this.
what do you exactly mean by that? could you clarify further…..
Sure. It works great in both Firefox and Safari. But in IE nothing happens and I get a javascript error that says “null is null or not an object.”
Also, so this function is essentially using “_blank” if it can’t open via javascript. Is there any way to set the window size?
i think in IE there might be some problem with establishing the externalinterface call or something is wrong with window.open in IE, i haven’t had any problems, is there a specific version of IE in which the problem happens.
navigatetoURL as far as i know doesn’t have parameters to change the window size.
[…] it might be because of popup blocker. To avoid popups from Flash i have written another post, Avoiding Popup Blockers Download the fla file here. […]
Yes! Finally something about radio broadcasting.