views:

292

answers:

1

I'm very new to AIR development, and have just started seriously building my first simply application. I'd like to open a new window to prompt the user for desired settings upon first run. In testing the new window and detecting its closed state, I've done the following (some jQuery code included):

The following code is used to open the new window upon running the main application (as soo as it opens).

$(document).ready(function(){
    var options = new air.NativeWindowInitOptions();
    options.type = air.NativeWindowType.UTILITY;
    var windowBounds = new air.Rectangle(200,250,300,400);

    //create the new window
    newHTMLLoader = air.HTMLLoader.createRootWindow(true, options, true, windowBounds);
    newHTMLLoader.load(new air.URLRequest("setup.html"));
    newHTMLLoader.window.opener = window;
    newHTMLLoader.window.nativeWindow.addEventListener(air.Event.CLOSE, handleNewSettings);
}

The code below is directly after the closing brace of the jQuery document.ready function. Its purpose is to handle the close event of the settings window. If it's closed without submitting - which is all I'm testing here so far - I want it to remove the event listener, as suggested by the manual to improve memory, and close the main application window (currently not visible).

function handleNewSettings(event){
    //remove the event handler from memory first...
    newHTMLLoader.removeEventListener(Event.CLOSE, arguments.callee);

    //this is my event handler code
    alert('yay');
    window.close();
}

I'm getting what appears to be an AIR runtime error popping up after I close the settings window:

An ActionScript error has occurred: "TypeError: Error #2007: Parameter type must be non-null. at flash.events::EventDispatcher/removeEventListener()"

I believe this error is related to application scope, but am not too versed in JS scoping rules either. If I comment out the removeEventListener line, it seems to run the code; however, I'm uncertain if I'm doing all of this the proper way or not. I tried to be detailed in my query, but the original question goes back to the title of the question.

+2  A: 

The error was due to a missing class (or is it namespace?)

newHTMLLoader.removeEventListener(Event.CLOSE, arguments.callee);

...should have been...

newHTMLLoader.removeEventListener(air.Event.CLOSE, arguments.callee);

I'm still unsure if this is the recommended or proper method of handling such things.

BrendonKoz