tags:

views:

109

answers:

1

I have two windows. Event called in the one window, but handler (listener) must be in the other window. Can this be done? If yes, how to?

+5  A: 

How the windows are created, is the second window which fires the event a child window created by the first window(one with the listener)?

Do you want to fire a custom event or use a extjs event?

You can add a custom event in different ways ex

var win = new xxxWindow();
win.addEvents('myevent');

Or

Ext.extend(xxxWindow, Ext.Window, {
    initComponent: function(){
        xxxWindow.superclass.initComponent.apply(this, arguments);
        this.addEvents('myevent');
    }
});

Then in your first window(one with listener and the parent of the second window) after creation of the second window

showSecondWindow: function(){
    var win = new xxxWindow();
    win.on('myevent', this.myEventHandler, this);
},

myEventHandler: function(arg1, arg2){
}

To fire the custom event from the second window

fireMyEvent: function(arg1, arg2){
    this.fireEvent('myevent', arg1, arg2);
}

Hope this solves your problem.

Arun P Johny
Events are a great way to communicate between components. Good answer.
Jonathan Julian