1. #1
    Sencha User
    Join Date
    Jun 2009
    Posts
    410
    Vote Rating
    2
    parky128 is on a distinguished road

      0  

    Default How to listen for custom events fired in application

    How to listen for custom events fired in application


    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:

    Code:
    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:

    Code:
    listeners: {
                logout: { fn: this._logoutHandler, scope: this }
            }
    But this wont work for me, can I use this listeners object to listen for custom events?

  2. #2
    Sencha - Sencha Touch Dev Team rdougan's Avatar
    Join Date
    Oct 2008
    Posts
    1,158
    Vote Rating
    6
    rdougan will become famous soon enough

      0  

    Default


    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:

    Code:
    this.getApplication().on({
        logout: this.logoutHandler,
        scope: this
    });
    Sencha Inc.
    Robert Dougan - @rdougan
    Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.

  3. #3
    Sencha User Saeven's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Canada
    Posts
    419
    Vote Rating
    1
    Saeven is on a distinguished road

      1  

    Question Same Question...

    Same Question...


    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).

    Code:
    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
    S. Alexandre Lemaire
    Senior Architect
    saeven.net consulting inc.

Thread Participants: 2