PDA

View Full Version : How to listen for custom events fired in application



parky128
25 Jan 2012, 4:35 AM
Hi,

I am just switching in the PR4 release into my application, and am restructuring my controller files as per the latest documentation.

I have a logout event being fired in my application, and in PR3 I would do something like this in the controller:


this._application.on( { 'logout': function() {

this._logoutHandler();
},scope: this});



I can still do this in PR4, but also note from the documentation I could setup a listeners config object like so:


listeners: {
logout: { fn: this._logoutHandler, scope: this }
}




But this wont work for me, can I use this listeners object to listen for custom events?

rdougan
25 Jan 2012, 10:34 AM
That should work, but just remember that he listeners must still be added onto the application instance, and not your controller (which is where they would be going if you put them inside the config: {} block). You should so something like this in your controller:


this.getApplication().on({
logout: this.logoutHandler,
scope: this
});

Saeven
15 Feb 2012, 10:53 AM
Hi,

I have the exact same question (problem). I have an application that contains a list, and I was hopeful to have that list's selection event fire out to an application-level listener (because they all fire a common routine).



Ext.application({
name: 'test',
launch: function() {
Ext.create("Ext.Panel", {
fullscreen: true,
layout: 'vbox',
items: [
{
xtype: 'list',
flex: 5,

store: new Ext.data.Store({
...
}),

listeners: {
select: function( view, record ) {
this.fireEvent( 'galleryLoad' );
}
},
....


Where would I add the app-level listener to listen to the galleryLoad event?

Thanks again.
Alex