Flex: Popup a Window with Javascript

I had the need to popup a browser window from my Flex application and wanted it to popup without toolbars, etc. I found some online examples that did it in different ways. Below is the solution I went with.

FlexPopup.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
   
   <mx:Script>
      <![CDATA[
         
         public function goToURLPopup(url:String,winName:String,w:int,h:int,toolbar:int,location:int,directories:int,status:int,menubar:int,scrollbars:int,resizable:int):void
         {
            var fullURL:String = "javascript:var myWin; if(!myWin || myWin.closed){myWin = window.open('" + url + "','" + winName + "','" + "width=" + w + ",height=" + h + ",toolbar=" + toolbar + ",location=" + location + ",directories=" + directories + ",status=" + status + ",menubar=" + menubar + ",scrollbars=" + scrollbars + ",resizable=" + resizable + ",top='+((screen.height/2)-(" + h/2 + "))+',left='+((screen.width/2)-(" + w/2 + "))+'" + "')}else{myWin.focus();};void(0);";
            var u:URLRequest = new URLRequest(fullURL);
            navigateToURL(u,"_self");
         }
         
      ]]>
   </mx:Script>
   
   <mx:Panel width="100%" height="100%" title="Flex Popup Example" paddingLeft="10" paddingTop="10">
      <mx:Button label="Google" click="goToURLPopup('http://www.google.com/', 'popup', 640, 480, 0, 0, 0, 0, 0, 1, 1)"/>
   </mx:Panel>
   
</mx:Application>


And here is my example:

No comments yet.

(will not be published)
Leave this field empty: