OK, I have been away from Flash for a little while now, and even when I was developing heavily in it I never used pop-up windows. I have recently run into a situation where I need them. Am I really so horribly behind that I missed the fact that Pop-Ups just don’t work from flash anymore if the user has an active blocker? Is there a way to make the browser register the onClick and not block it if the user clicks it?
Popups do indeed work from Flash. ![]()
In order for the browser to trust the Flash object, thus allow popup windows, the Flash object needs to be part of the DOM’s trusted display list. Normally when you add a Flash object to the document it is contained in it’s own “container” and as a result the browser will not trust the Flash object. The way to fix this is to set the wmode property of the Flash object to “opaque” or “transparent” (obviously don’t use transparent unless you really need to), that will plop the Flash object in the DOM’s display list as a trusted object, and you can then launch popups without restriction (although a mouse-click is still required, no auto-launch popups are allowed, not even in JavaScript).
When you set the wmode to “opaque” or “transparent” you will notice that Firefox will show a dotted line around the Flash object when it gains focus (when you click on it), the way to prevent that is to set the “outline” style of the object to “none” (FYI, that also works for regular HTML links).
Here is an example of the HTML:
[highlight=“XHTML”]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html lang=“en” xml:lang=“en” xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<title></title>
<meta http-equiv=“content-type” content=“text/html; charset=UTF-8”/>
<meta http-equiv=“content-language” content=“en-gb”/>
<meta name=“mssmarttagspreventparsing” content=“true”/>
<style type=“text/css”>
object
{
width:800px;
height:500px;
display:block;
}
object:focus
{
outline:none;
}
</style>
[removed]
function openWindow()
{
if( window.open( “some.site.com”, “windowname”, “options” ) )
{
return true;
}
return false;
}
[removed]
</head>
<body>
<object id=“flash” type=“application/x-shockwave-flash” data=“movie.swf”>
</object>
</body>
</html>[/highlight]
If you are publishing the Flash movie for Flash Player 8 or higher then you should take advantage of the ExternalInterface class to call your JavaScript functions. Not only is it the cleanest way to do things, it also allows you to receive data back from the functions. For example, if for some reason that popup window fails to launch then “false” will be returned to Flash and you could present the user with a message of some kind, if the popup launches fine then “true” will be returned.
[highlight=“ActionScript 2.0”]import flash.external.ExternalInterface;
function myFunc():Void
{
var result:Boolean = Boolean( ExternalInterface.call( “openWindow” ) );
if( result )
{
// popup launched
}
else
{
// popup failed to launch
}
}[/highlight]
You don’t even need any JavaScript code, you can open a window directly from Flash (although you won’t get any data returned).
[highlight=“ActionScript 2.0”]import flash.external.ExternalInterface;
function myFunc():Void
{
var url:String = “http://www.ultrashock.com”;
var windowName:String = “mywindow”;
var windowOptions:String = “width:800,height:600”;
ExternalInterface.call( “window.open”, url, windowName, windowOptions );
}[/highlight]
One other thing to keep in mind: Your Flash object will need to have an id in order for the ExternalInterface class to work. Also, check if the ExternalInterface can actually be used by making sure ExternalInterface.isAvailable is true, if ExternalInterface is not available then you should fall-back to the nasty getURL way of calling JavaScript from Flash. You might also want to pass a flashVar to the movie letting your code know if JavaScript is enabled in the browser.
- 04 February 2008 09:54 PM
-
[QUOTE=tiran;720981]So the only place this seems to still cause me problems is FireFox on a Linux box (no idea why there) and Safari (which I think there is a completely different work around for).
I will look into those issues over the next day or so if no one posts any solutions in the meantime.
Which browser versions are you using?
Safari is a pain in the ass, period. I hate it more than Internet Explorer at the moment.
- 05 February 2008 04:04 PM
-
Looks like a good fall-back to use if Safari blocks the popup, although if navigateToURL is used it looks like it will just open the requested page in a new browser window instead of a “popup” window. I guess that is fine though, at least the requested page will be shown one way or another.
Does that solution work for Firefox/Linux as well?
- 05 February 2008 05:29 PM
-
Hmm. I will put together a working example that should hopefully work in Safari (I think that example you linked to could be cleaned up a bit)... then we can try and sort out the Linux problem if you are up for it. It seems strange that Firefox on Linux is having problems though, I would have thought Firebox would behave the same with popups no matter what OS is what running on. My initial guess is that it is an issue with ExternalInterface on Linux so I will look into that.
- 05 February 2008 07:12 PM
-
Working
• Firefox 2.0 - Mac
• Firefox 2.0 - Windows
• Firefox 3.0 Beta 2 - Windows
• Internet Explorer 6.0 - Windows
• Internet Explorer 7.0 - Windows
• Netscape 8.1 - Windows
• Opera 8.52 - Windows
• Opera 9.25 - Windows
• Safari 523.10 - Mac
Some browsers seem to open new windows/tabs instead of actual popups, but that is better than the popups being completely blocked. That seems to be the most common browsers/systems covered anyway.
Not Working
• Firefox 2.0 - Linux
- 07 February 2008 12:22 AM
-
- Log in or join for free to make a comment.


