Using the ExternalInterfaceUtil

samac1068's Avatar

samac1068

28 Sep, 2011 12:51 PM

I know this should be a simple question, but for the life of me I can figure as to why my event isn't firing. This is what I have which sits on my main mxml file. I am using Robotlegs with signals (latest of both)

MXML:

private function init():void
{

ExternalInterfaceUtil.addExternalEventListener("window.onunload", pageClosing, "unloadFlex");

}

public function pageClosing():void
{

  trace("I've been called because this page is unloading.");

}

Of course I have the ExternalInterfaceUtil class in my appropriate folder. Here is the version I have:

ExternalInterfaceUtil:
package
{

import flash.external.ExternalInterface;

public class ExternalInterfaceUtil
{
    public static function addExternalEventListener( qualifiedEventName:String, callback:Function,callBackAlias:String ):void
    {
        if (ExternalInterface.available)
        {
            try
            {
                ExternalInterface.addCallback( callBackAlias, callback );
                var     jsExecuteCallBack:String = "document.getElementsByName('"+ExternalInterface.objectID+"')[0]."+callBackAlias+"()";
                var jsBindEvent:String = "function(){"+qualifiedEventName+"= function(){"+jsExecuteCallBack+"};}";
                ExternalInterface.call( jsBindEvent );
            }
            catch (e:Error)
            {
                Alert.show(e.message);
            }
        }
    }
}

}

My problem is the trace is never fired. If I close the window by the X button, navigate to another page, or select my close button I have in my application. It is completely ignored. I wondering if I am missing something. I know this forum is for RL, but I was wondering if I'm added my call to the ExternalInterfaceUtil in the wrong location. Any help would be greatly appreciated.

  1. 1 Posted by samac1068 on 28 Sep, 2011 01:07 PM

    samac1068's Avatar

    Disregard. I've found a small hack to work around the lack of call.

  2. samac1068 closed this discussion on 28 Sep, 2011 01:07 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac