Saturday, 13 July 2013

How to fire an Application level events in Sencha Touch 2

Today, we are going to see how we can fire an application level events that any controllers in the Sencha Touch application can listen on it. Let's see the demontration with the working example

First, let's add the application level events code using fireevent() method, which will fire application level event with name 'globalevent'.
MyApp.app.fireEvent('globalevent');
This above code follows the following format {<application name>.<app folder name>.fireEvent(<global EventName>)}.


Next, we are going to see the controller code, which will listen the application level event with name 'globalevent'. Here is the code
Ext.define('MyApp.controller.MyController', {
    extend: 'Ext.app.Controller',

    onGlobalevent: function () {

        Ext.Msg.alert('Global Event Fired');

    },

    init: function (application) {

        application.on([{
            event: 'globalevent',
            fn: this.onGlobalevent,
            scope: this
        }]);
    }
});

Here is the output, when i run the above code in Google Chrome.



Hope, you enjoyed this Post.

No comments:

Post a Comment