12 Replies Latest reply on Aug 19, 2009 8:23 PM by NSurveyor

    Problem closing popup window in flash player




      I'm new to the forum so please bear with me. I posted this in the actual "Flash" forum yesterday but I realized afterward that the ActionScript forum would be a better place to post the question (sorry about that). I'm a web designer but I don't use a lot of Flash. I'm sure this will change as time goes on. For now, I'm still using an old version of Flash MX on my Mac - Flash MX version 6. But I don't think this has anything to do with the problem I'm experiencing. I designed a flash animation for my wife's website back in 2004 and it has always worked perfectly up until installing the most recent Flash Player just a few days ago. Here's the problem:


      On the main page of my wife's website, we have a special link called "view presentation". When you click on that link, a smaller, new browser window pops up in front of the main page (the window sits "over top" of the main page - a typical pop up window). Inside of this new pop up window is the flash animation (the actual swf file). Inside of the HTML code for the pop up window, I have coded the following javascript:


      function closeWin() {

         if (document.images) {





      The above script, closeWin() is called from a button called "Quit" that the user clicks on in the actual swf file inside of the pop up window. Here is the code from the swf ActionScript:


      on (release) {


          getURL("javascript:closeWin();", "_self");



      This has always worked perfectly right up to Flash Player version - the window closed as soon as the user clicked on the button. But now, with the most recent Flash Player installed, it no longer works. The pop up window no longer closes.


      Obviously, something has changed in this latest version of Flash Player which is preventing this from working. Does anyone have any ideas on how I can fix this?


      Any help would be greatly appreciated. Thank you so much,


        • 1. Re: Problem closing popup window in flash player
          NSurveyor Level 2

          Are you sure it's a Flash player issue? I tried a similar script (seen at http://lhsmath.co.cc/js_selfclose.html ):


          onMouseDown = function(){


          And it seemed to work both on  and Using a function closeWin() defined in the HTML gave the same result.


          I would try using "javascript:alert('test');" to see if the javascript is getting through. Then check if self.close() works. If it is, there's got to be something wrong with "document.images". On the chance that all of them fails, perhaps it is a result of security changes? In that case, you have a couple of other options. See: http://www.adobe.com/devnet/flash/articles/external_interface_print.html

          1 person found this helpful
          • 2. Re: Problem closing popup window in flash player
            mikewilson4 Level 1

            Thanks so much for your help - in your example, I looked at the actual HTML code of your page at:




            There is no javascript anywhere in your HTML code that I can see. My pop up window has an actual javascript "closeWin()" (which is just basically the javascript command "self.close" called after a few checks) in the HTML. My swf file calls that javascript externally, I guess - through "getURL()" in the swf file. There seems to be a problem with the swf file communicating with the javascript in the HTML of the pop up window - almost like flash player is preventing the "self.close" portion from working (security changes?). I took out the "document.images" part of the javascript code but it makes no difference.


            We have one computer here running flash player and it works fine on that machine but on my computer running flash player, the window just won't close.


            It looks like I may have to use the ExternalInterface class but I don't think Flash MX version 6 can handle that?


            Also, I never coded allowScriptAccess in the HTML pop up code but the documentation you pointed me to says that if allowScriptAccess is not explicitly specified by an HTML page, the default value for the embedded SWF file is set to "sameDomain" in Flash Player 8 and to "always" in earlier versions so this shouldn't make any difference.


            I'm at a real loss. Can you try adding the same closeWin() javascript that I'm using into your HTML again and call that javascript from your swf file using getURL to see if does in fact, work under I can't see how it would work for you but not for me.


            Thanks again,


            • 3. Re: Problem closing popup window in flash player
              NSurveyor Level 2

              Here it is with JavaScript in the HTML: http://lhsmath.co.cc/js_selfclose2.html

              Wait, does that mean, that my version worked without the JavaScript in the HTML on your problematic machine? If this is the case, then I am puzzled. Could you provide me with a link to your wife's site?


              ExternalInterface is not available for Flash MX so that won't work for you, unforunately.


              Perhaps it is not the flash player, but some other setting specific to that particular machine? Try viewing the site from a different machine that is upgraded. Or, see if the problem persists when you downgrade the Flash Player: http://kb2.adobe.com/cps/142/tn_14266.html

              1 person found this helpful
              • 4. Re: Problem closing popup window in flash player
                mikewilson4 Level 1

                Well, yours works perfectly - thanks so much for trying this for me. I don't know what's going on. I wonder what would happen if you took the "alert" out and just tried to close the window without the alert popping up first? Maybe that would be the difference - with Flash Player seeing the alert as a "warning" first before the window just automatically closes. Perhaps this is a possibility?


                Also, when you are calling the javascript in the HTML code from your swf file, do you have your swf file coded like this:


                getURL("javascript:closeWin();", "_self");


                I have a feeling that the alert which pops up first is making the difference as to why your file is working and my file is not working.


                I have to step out for a while but I will check in later in the afternoon. Thanks again - you have been so very helpful.



                • 5. Re: Problem closing popup window in flash player
                  mikewilson4 Level 1

                  Actually, the more I think about this, the more I think that your alert box that pops up is what the difference is. So having said that, do you have your getURL() function coded to put the alert up first and then call the closeWin() function afterward in the HTML?


                  I think if I add an alert into the getURL function that says something like "Are you sure you want to close the window?" with a yes/no, then it will work.


                  I have it coded like this right now but I don't know exactly where to put the "alert" call:


                  getURL("javascript:closeWin();", "_self");


                  Thanks again,


                  • 6. Re: Problem closing popup window in flash player
                    NSurveyor Level 2

                    I actually had a mistake on my last test. It actually embedded the original swf, instead of the one with external javascript. So here are the tests I have so far:


                    1. All in flash with alert: http://lhsmath.co.cc/js_selfclose.html
                    2. JavaScript with alert: http://lhsmath.co.cc/js_selfclose2.html
                    3. Javascript without alert: http://lhsmath.co.cc/js_selfclose3.html


                    I think it's kind of weird for the alert to make a difference. In fact, for the third test, even without the alert, it still works for me. But, if you want to try it anyway, you can either add it to the JavaScript in the HTML as: alert("Really? You really want to do that?"); or in ActionScript:


                    getURL("javascript:alert('Really? You really want to do that?'); closeWin();", "_self"); 


                    Could you possibly send a link to the problematic page? Or at least a simplified version to see if there could possibly be anything else interfering?

                    • 7. Re: Problem closing popup window in flash player
                      mikewilson4 Level 1

                      Hello and thanks again for all your help. All of your examples work on my computer. I just don't get it. It is driving me crazy. I installed the latest Flash Player version on our other computer (a Power PC Mac) which is running Mac OS X 10.4.11 and my pop up still works. On my Intel Mac computer running Mac OS X 10.5.8, it won't work.


                      The only thing I'm thinking at this point is that I installed an Apple Security Update 2009-004 on my Intel Mac a few days ago (around the same time as I updated the Flash Player) but that same security update has not yet been installed on the Power PC Mac. So maybe this has nothing to do with the Flash Player after all. But why would your examples still work on my computer if this were the case?


                      Also, I don't have this coded into the swf the way you do and maybe this is part of the problem:


                      <param name="allowScriptAccess" value="sameDomain">


                      Let me work on this a bit and I will get back to you shortly - I want to try installing the Apple Security Update on the Power PC Mac to see if it makes any difference.


                      Thanks so much for your help once again,


                      • 8. Re: Problem closing popup window in flash player
                        NSurveyor Level 2

                        So, on this one computer, all of my examples work while your own does not? If that is the case, I would not attribute the problem to an Apple Security update. There has to be something that is making a difference between my code and yours. I removed the allowScript stuff from the HTML (in the third test) and it still seems to work, so it's probably not that. Is it not possible to give a link to the website because I feel looking at that might help clear the issue, or at least the HTML code.

                        • 9. Re: Problem closing popup window in flash player
                          mikewilson4 Level 1

                          Well, thanks to your help - I got it solved. It's not the Security Update, it's not javascript, it's not the difference in flash versions, it's nothing in the ActionScript itself or any of the other things I/we thought it might have been. I looked really closely at your HTML code and compared it to mine and changed it so that it was almost exactly the same as what you had coded - here's what made the difference (I've bolded the changes so you can see the differences):


                          old code:


                          <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" id="tour" width="600" height="450" align="top">

                          <param name="movie" value ="tour.swf">

                          <param name="quality" value ="high">

                          <param name="bgcolor" value ="#ffffff">

                          <embed name="tour" src="tour.swf" quality ="high" bgcolor ="#ffffff" width ="600" height ="450" align ="top" type ="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" swLiveconnect="true"></embed >

                          </object >


                          new code:


                          <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="600" height="450" id="tour" align="top">

                          <param name="allowScriptAccess" value="sameDomain">

                          <param name="movie" value="tour.swf">

                          <param name="quality" value="high">

                          <param name="bgcolor" value="#ffffff">

                          <embed src="tour.swf" quality="high" bgcolor="#ffffff" width="600" height="450" name="tour" align="top" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>



                          Now works perfectly - the pop up window closes every time (I also took out swLiveconnect="true" - not sure where that ever came from).


                          I'm not exactly sure how the above changes could make it work but they did so I am thrilled that you were kind enough to help out. If you have any ideas as to what actually did make the difference, please let me know as I am very curious. Maybe is was the "codebase" line? Seems like adding in the "allowScriptAccess" also had some sort of effect.


                          Thanks again,


                          • 10. Re: Problem closing popup window in flash player
                            NSurveyor Level 2

                            It's good to know that my intuition was right in that it was the HTML code! But I'm still puzzled by the discovery, as I have taken your old code, and it still works for me. I would be curious to know if this now fails on that same problematic machine: http://lhsmath.co.cc/js_selfclose4.html


                            If you really want to know which line did it, try changing them all back, and then making each change separate and testing to see if it works. Because at this point, I really have no idea.

                            • 11. Re: Problem closing popup window in flash player
                              mikewilson4 Level 1

                              Yes - your intuition was definitely correct! The example you just gave me at:




                              Works perfectly on the machine that was giving me problems before - my own Mac running Mac OS X 10.5.8 with the latest Security Update 2009-004 (I also tested it on the other machine running Mac OS X 10.4.11 without the latest Security Update and it works fine on that one, too).


                              I'll try changing the lines around and see if I can narrow down the actual line that made the difference. The pop up won't close if I load the page locally on my hard drive but it works perfectly on the web (due to the allowScriptAccess="sameDomain" parameter).


                              So it all works and I thank you so kindly for taking all the time out to help me. I will do some experimenting and see if I can find out which line was causing the problem and post back.


                              Thanks again for all your help,


                              • 12. Re: Problem closing popup window in flash player
                                NSurveyor Level 2

                                You're welcome, and I look forward to hearing what you find.