The Ultrashock Ultra Bundle
  • Home
  • Community
  • Forum
  • Flash
  • ActionScript
  • Thread
  •  
  • Previous topic
  • Next topic
Sign up to post

Flash
 ActionScript

  • tiran Author 
    • 22106 
    • 1 
    • 65 
    Popups From Flash - Solution
    onlyreal

    Last reply Oct 20 2011, 10:42 PM

    by onlyreal

    Posted: Feb 04 2008, 07:05 PM

    by tiran

     

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?

  65 REPLIES
  • of
  • 5
next last page
Nutrox
1  
Nutrox

Popups do indeed work from Flash. yes

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.

good

  • 04 February 2008 09:54 PM
  •  
Nutrox
2  
Nutrox

PS: Moved thread to the ActionScript forum and made it sticky seeing as this question is being asked quite frequently at the moment.

  • 04 February 2008 10:49 PM
  •  
Laveklint
3  
Laveklint

nice posts wink

  • 05 February 2008 02:50 AM
  •  
tiran Author 
4  
tiran

excellent, thanks Nutrox.

  • 05 February 2008 09:09 AM
  •  
Anik
5  
Anik

coolness of the Si.

  • 05 February 2008 09:50 AM
  •  
sims11tz
6  
sims11tz

Nutrox!  Best tip I have heard in a long time, thanks!

  • 05 February 2008 12:03 PM
  •  
tiran Author 
7  
tiran

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).

  • 05 February 2008 03:39 PM
  •  
Nutrox
8  
Nutrox

[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. big grin

  • 05 February 2008 04:04 PM
  •  
tiran Author 
9  
tiran

Cool, this solution seems to work for safari:

Workaround for Safari Blocking Flash Initiated Pop Ups

  • 05 February 2008 05:21 PM
  •  
Nutrox
10  
Nutrox

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
  •  
tiran Author 
11  
tiran

Does that solution work for Firefox/Linux as well?

nope, it actually does evil things on Firefox/Linux….It blocks it and tells the user 2 pops have been blocked from one click.

  • 05 February 2008 06:07 PM
  •  
Nutrox
12  
Nutrox

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
  •  
tiran Author 
13  
tiran

Thanks for the work Nutrox, still getting no love on FF/Linux, but would like to confirm those issues on another box. Anyone else have FF on Linux that could test?

  • 06 February 2008 12:42 PM
  •  
Nutrox
14  
Nutrox

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
  •  
tiran Author 
15  
tiran

cool, I’m still working on getting someone else to test on another Linux box.

  • 08 February 2008 12:29 PM
  •  
  •   Log in or join for free to make a comment.

Page 1 of 5

  • of
  • 5
next last page
Topic actions
  •  Share on Facebook
  •  Share on Twitter
Topic Categories
  •  Show All Topics
  •  Development
    •  Server Side
    •  Client Side
  •  Creative Software
    •  Web
    •  Video
    •  3D
    •  Illustrator
    •  Photoshop Battles
    •  Photoshop
  •  Design
    •  Typography
    •  Resources & Insight
    •  Checkpoint
  •  Career
    •  Copyright Matters
    •  Advice & issues
    •  Job Seekers
    •  Job Offers
  •  Flash
    •  UltraMath
    •  OOP
    •  Third Party Tools
    •  Open Source alternatives
    •  Data Communication
    •  Components
    •  Flex
    •  AIR
    •  Flash Lite
    •  Flash Professional
    •  Flash Newbie
    •  ActionScript
    •  XML
  •  Lounge
    •  Polls
    •  Random Chat
    •  Showcase And Critique
    •  BombShock Award Nominations
  •  Community Essentials
    •  BombShock Award Winners
    •  Tutorials
    •  Interviews
    •  News
    •  Bitmap tutorials
Popular Topics
  • Sort by: 
  • Activity
  • Views
  • Comments
  • Likes
Advertise with us
  • Your advertisement here!
  • loading
Ultrashock
  • Creative Assets
  • Community
  • Blog
  1. Home
  2. Forum
+/-
Creative Assets
  • Categories
  • Contributors
  • How to buy
Make Money
  • Commission Rates
  • Referral Program
  • Contributor Program
Community
  • Activity Feed
  • Forum
  • Profiles
About
  • Quick Tour
  • Our History
  • Banners & Logos
Support
  • Contact Ultrashock
  • Advertise with us
  • Legal Information
  •  Keep up to date
  • Flash 775  Flash
  • Audio 6,481  Audio
  • Vector 2,130  Vectors
  • Image 12,338  Images
  • Creative Assets 21,724  Assets
  • Profiles 282,659  Members
  • Topics 93,762  Topics
  • Blog 4  Blog
  • Facebook 1,680  Facebook
  • Twitter 1,165  Twitter
  • Join our FREE monthly newsletter!
  • Archive
  • Invalid email address. Please try again.
Subscribe
  • ©2012 Ultrashock LLC - All rights reserved
  • Terms of Use
  • Privacy Policy
  • Switch to dark theme
  • RSS Feeds
  • Top

©2012 Ultrashock LLC - All rights reserved

Printed on Sat, February 04, 2012 - 19:00:09