0

I have a small application created by Sencha Architect 2. I noticed several times already that I can very well override onLaunch of both Controller and Application object, the function is never called. I'm using trial version 2.0.0, build 412. Here is the application code:

Ext.Loader.setConfig({
    enabled: true
});

Ext.application({
    views: [
        'MyContainer',
        'MyGridPanel'
    ],
    autoCreateViewport: true,
    name: 'MyApp',

    onLaunch: function() {
        var container = Ext.getCmp ('glbContainer');

        var cfg = [
        { dataIndex: 'ID', text: 'ID' },
        { dataIndex: 'DISPLAYNAME', text: 'Displayname' }
        ];

        var theGridPanel = this.getComponent ('theGridPanel');

        var config = [];


        for (var jj=0; jj<cfg.length; jj++) {
            var configElem = {};
            configElem.xtype = 'gridcolumn';
            configElem.dataIndex = cfg [jj].dataIndex;
            configElem.text = cfg [jj].text;
            configElem.width = 200;
            config.push (configElem);
        }

        alert (config.length);

        theGridPanel.reconfigure (config);

    }

});
sha
  • 17,824
  • 5
  • 63
  • 98
kaidentity
  • 609
  • 4
  • 10
  • 26

2 Answers2

2

I don't think we have a onLaunch method to override. It should be launch. Have a look at the documentations. There is no onLaunch property for Application or Controller class. Quoting from the docs:

launch method: Called by the Controller's application immediately after the Application's own launch function has been called. This is usually a good place to run any logic that has to run after the app UI is initialized. See also init, which is called before the Application's launch function.

Example:

Ext.application({
    name: 'MyApp',
    launch: function() {
        Ext.create('Ext.container.Viewport', {
            items: {
                html: 'My App'
            }
        });
    }
});
Abdel Raoof Olakara
  • 19,223
  • 11
  • 88
  • 133
  • Hi, I'm perfectly willing to follow your advice and I will definitely try launch, but there is an onLaunch for both Application and Controller: http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Application. Documentation says: "This is a template method. a hook into the functionality of this class. Feel free to override it in child classes." – kaidentity May 02 '12 at 16:00
  • Ahh!! My utter mistake! Now I understand what you are trying to do! – Abdel Raoof Olakara May 02 '12 at 16:05
2

Launch is the right method to use here.

While Application is a Ext.app.Controller it doesn't always do exactly what a controller does. Also note that your not using Ext.define here to define your application and you shouldn't. You are however calling a method Ext.application({ config });

Proper way to set an Application's launch method

Ext.application({
    name: 'MyApp',
    controllers: [
        'MyController'
    ],

    launch: function() {

    }

});

Proper way to set a controller's launch method

Ext.define('MyApp.controller.MyController', {
    extend: 'Ext.app.Controller',

    onLaunch: function() {

    }

});
Phil Strong
  • 1,014
  • 9
  • 11