Search code examples
javascriptswfaddress

Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOMEventTarget.dispatchEvent]


I am very new to javascript, so forgive me for my ignorance.

I am currently using SWFAddress to build deeplinking for a flex application. The problem is that the browser history functionality does not work in IE9.

I would like to fix that, and it seems like it shouldn't be a difficult fix.

When I debug the script in firefox, I get this error message:

Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOMEventTarget.dispatchEvent]
this.dispatchEvent(new SWFAddressEvent(type)); 

This points to this bit of code as the culprit:

_dispatch = function(type) {
            this.dispatchEvent(new SWFAddressEvent(type));
            type = type.substr(0, 1).toUpperCase() + type.substr(1);
            if(typeof this['on' + type] == FUNCTION)
                this['on' + type]();
        },

I have checked and confirmed that the SWFAddressEvent object is instantiated correctly without any problems.

The problem seems to lie here:

this.dispatchEvent = function(event) {
    console.log(event);
        if (this.hasEventListener(event.type)) {
        console.log(event);
            event.target = this;
            for (var i = 0, l; l = _listeners[event.type][i]; i++)
                l(event);
            return TRUE;           
        }
        return FALSE;
    };

It seems that for some reason, dispatchEvent does not receive the SWFAddressEvent that was created.

Can someone explain what that error message means? And why is it that when the page first loads, it is able to dispatch 3 events properly, but when it comes to dispatching further events, it seems to fail?


Solution

  • It seems to me that the problem is the reference to this in:

    this.dispatchEvent(new SWFAddressEvent(type));
    

    This part is executed in an event handler so this is not SWFAddress, but Window.

    I replaced it with SWFAddress.dispatchEvent(new SWFAddressEvent(type)); and that fixed it - hover I am not a JS expert.

    The first three event are generated in a different way than the one that creates NS_ERROR_ILLEGAL_VALUE.