0

Im trying to create a browser popup window with some text, rather than using the Alert.show() or Flash Player level popups.

I have been looking around, and tried some stuff with URI Data Scheme, but thought one of you guys might have done something similar before.

UPDATE: Answered Myself Below

Drenai
  • 11,315
  • 9
  • 48
  • 82
  • 1
    Does it have to be 'specified' in swf? My approach would be to have all the code done in html/javascript and have Flex call a javascript function using ExternalInterface to open your window. – J_A_X Jul 06 '11 at 16:10
  • @J_A_X - yeah, have to specify it in the swf - thats all were editing at this point - updating the JS is not really an option. From what ive done so far from above, Im pretty sure it's doable - just not very JS savvy – Drenai Jul 06 '11 at 16:12

3 Answers3

1

You can use Flex's externalInterface API to call javascript functions. and thus to trigger a new popup dialog.

http://learn.adobe.com/wiki/display/Flex/External+Interface

http://www.quirksmode.org/js/popup.html

http://blog.flexexamples.com/2008/03/09/calling-javascript-functions-from-your-flex-applications-using-the-externalinterface-api/

UPDATE:

var urlstr:String = "javascript:NewWindow=window.open('"+<any string> +"','newWin','width=400,height=300,left=0,top=0,toolbar=No,location=No,scrollbars=No,status=No,resizable=No,fullscreen=No');  NewWindow.focus();void(0);");

    var url:URLRequest = new URLRequest(urlstr);
Satish
  • 6,457
  • 8
  • 43
  • 63
  • thanks for that, but adding JS code to the html page isn't really an option - thats why im looking for a Flex only solution. Thanks anyhow – Drenai Jul 06 '11 at 16:14
  • You dont' need to add JS code to html page. you can have JS code in your AS3/MXML itself. – Satish Jul 06 '11 at 16:16
  • Oh, yeah, updated my question - getting closer to what I want – Drenai Jul 06 '11 at 16:37
0

And you want the Flex window to stay open and just popup a new one right? From what I remember, this is not possible with Flash since it needs to go through Javascript (window.open), however, you might be able to call it directly using ExternalInterface:

if (ExternalInterface.available) 
{
   ExternalInterface.call("window.open", "http://www.adobe.com", "win", "height=200,width=300,toolbar=no,scrollbars=yes");
}

As for the url, you can specify your own or use the uri data scheme and it should work.

J_A_X
  • 12,857
  • 1
  • 25
  • 31
  • Hey, put an answer I found in the question - works fine in Firefox, just need to test Chrome and IE now – Drenai Jul 06 '11 at 16:54
0

The following code does the trick:

<fx:Script>
    <![CDATA[
        import flash.net.navigateToURL;

        private function urlJump():void{

            var url:URLRequest = new URLRequest("javascript:NewWindow=window.open(''," +
                "'newWin','width=400,height=300,left=0,top=0,toolbar=No,location=No,scrollbars=No,status=No,resizable=No,fullscreen=No');  " +
                "NewWindow.focus();void(0); " +
                "NewWindow.document.write('hello');");

            navigateToURL(url, "_self" );

        }           
    ]]>
</fx:Script>
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<s:Button click="urlJump()" />

Drenai
  • 11,315
  • 9
  • 48
  • 82