Home > Flash development > External Interface with javascript confirm “bug”

External Interface with javascript confirm “bug”

February 4th, 2008 Randy Leave a comment Go to comments

I am working with External Interface in Flash and I encountered a problem which I am recreating here. Below you should see a Flash based (AS3) button that says "Show Alert". If you click it a javascript confirm dialog will appear. You will also notice that the button stays in it's down state. If you wait more that 15 seconds to confirm, the Flash Player complains that a script has been running too long. This is unexpected since I would assume that clicking a button in Flash and Javascript responding after a confirm dialog should be an asynchronous event. I tried this using the "MouseEvent.MOUSE_UP" event and got the same result. See below for the error response, javascript and actionscript code.

 

(note: you should see "from javascript" when you agree to the confirmation dialog box if the call succeeds. If the call fails and you have the debug Flash Player version installed you should see an alert window with the error below. If you do not have the debug player and the call fails you will see nothing.)

Error: Error #1502: A script has executed for longer than the default timeout period of 15 seconds.
at ()
at flash.external::ExternalInterface$/_evalJS()
at flash.external::ExternalInterface$/call()
at showAlert_fla::MainTimeline/handleClick()

Funny though. Flex has no problem:

JavaScript:
  1. function fromFlash(){
  2.     if(confirm("Talk to Flash?")) toFlash();
  3. }
  4.  
  5. function toFlash(){
  6.     thisMovie("showAlert").toFlash("from javascript");
  7. }
  8.  
  9. function thisMovie(movieName) {
  10.     if (navigator.appName.indexOf("Microsoft") != -1) {
  11.         return window[movieName]
  12.     }
  13.     else {
  14.         return document[movieName]
  15.     }
  16. }

Actionscript:
  1. alertButton.addEventListener(MouseEvent.CLICK, handleClick);
  2.  
  3. ExternalInterface.addCallback("toFlash", responseFromJavascript);
  4.  
  5. function handleClick(p_evt:MouseEvent):void{
  6.     responseTF.text = "";
  7.     ExternalInterface.call("fromFlash");
  8. }
  9.  
  10. function responseFromJavascript(p_response:String):void{
  11.     responseTF.text = p_response;
  12. }

Categories: Flash development Tags:
  1. Manu
    February 27th, 2008 at 11:15 | #1

    Hello Randy,
    I am having the problem you have posted here with some differences.
    First of all it's happening with Flex 3.

    To reproduce the problem try to launch from a Flex application a new browser window, with modal property yes, through JavaScript.

    Some code to help you:

    function launchBrowserWindow()
    {
    if (window.showModalDialog)
    {
    window.showModalDialog("FCKEditor/fckEditor.html","name","dialogWidth:900px;dialogHeight:560px");
    } else {
    window.open('FCKEditor/fckEditor.html','Editor de contenidos','width=900, height=560, toolbar=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no , modal=no, top=0, left=0');
    }
    }

    It seems that having this property, makes the popup not replying to the Flash player, causing the error you commented.

    I am trying to have a workaround about this, but I am not having much luck at the moment, maybe having a try{}catch {} statement may help...

    Cheers,
    Manu

  2. Randy
    February 27th, 2008 at 16:46 | #2

    @Manu: Interesting ... I worked around my problem calling the confirm through javascript before involving Flash which worked for me. I submitted this as a Flash bug to Adobe. You should submit this the the flex bug database.

  1. No trackbacks yet.