1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    3
    Vote Rating
    0
    schmidt@archomedia.com is on a distinguished road

      0  

    Default Answered: Extend Ext.Application

    Hi,

    based on the pandora example I tried to extend Ext.app.Application like shown in the section "Deriving from Ext.app.Application" here. I get something like this:

    Code:
    Ext.define('AbstractApplication', {
        extend: 'Ext.app.Application',
    
        constructor: function (config) {
            config = config || {};
            Ext.apply(this, config);
    
            var me = this;
            me.callParent(config);
        },
    
        launch:      function () {
            var me = this;
            me.initBar();
        },
    
        bar:         function () {
            console.log('bar called');
        }
    });
    
    
    Ext.application({
                        extend: 'AbstractApplication',
                        name:   'Pandora',
    
                        autoCreateViewport: true,
    
                        models:      ['Station', 'Song'],
                        stores:      ['Stations', 'RecentSongs', 'SearchResults'],
                        controllers: ['Station', 'Song'],
    
                        launch: function () {
                            var me = this;
                            me.callParent();
                        }
                    });
    But I get an error saying 'Error: this.callParent() was called but there's no such method (onBeforeLaunch) found in the parent class (Ext.app.Controller)' on line 'Ext.application > launch > me.callParent'

    If I do it the way described here with
    Code:
    Ext. onReady
    it works faultless. May somebody please tell me why the example from the docs is not working or what I'm doing wrong?

  2. Ext.application() is in fact will:
    1. Load Ext.app.Application class.
    2. On Ext.ready, it will create an instance of Ext.app.Application.
    Code:
    Ext.application = function(config) {
        Ext.require('Ext.app.Application');
    
    
        Ext.onReady(function() {
            new Ext.app.Application(config);
        });
    };
    So with your code:
    Code:
    Ext.application({
        extend: 'AbstractApplication', // (1)
        name:   'Pandora',
    
    
        autoCreateViewport: true,
    
    
        models:      ['Station', 'Song'],
        stores:      ['Stations', 'RecentSongs', 'SearchResults'],
        controllers: ['Station', 'Song'],
    
    
        launch: function () {
            var me = this;
            me.callParent(); // (2)
        }
    });
    (1): This line has no effect because Ext.app.Application has no config named 'extend'.
    (2): This line cause the error you mentioned in your post. Because Ext.app.Application is extended from Ext.app.Controller so this line will call Ext.app.Controller.launch(). However, because Ext.app.Controller does not define launch() method so it will cause error.

  3. #2
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Vote Rating
    112
    Answers
    347
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default

    Ext.application() is in fact will:
    1. Load Ext.app.Application class.
    2. On Ext.ready, it will create an instance of Ext.app.Application.
    Code:
    Ext.application = function(config) {
        Ext.require('Ext.app.Application');
    
    
        Ext.onReady(function() {
            new Ext.app.Application(config);
        });
    };
    So with your code:
    Code:
    Ext.application({
        extend: 'AbstractApplication', // (1)
        name:   'Pandora',
    
    
        autoCreateViewport: true,
    
    
        models:      ['Station', 'Song'],
        stores:      ['Stations', 'RecentSongs', 'SearchResults'],
        controllers: ['Station', 'Song'],
    
    
        launch: function () {
            var me = this;
            me.callParent(); // (2)
        }
    });
    (1): This line has no effect because Ext.app.Application has no config named 'extend'.
    (2): This line cause the error you mentioned in your post. Because Ext.app.Application is extended from Ext.app.Controller so this line will call Ext.app.Controller.launch(). However, because Ext.app.Controller does not define launch() method so it will cause error.

  4. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    3
    Vote Rating
    0
    schmidt@archomedia.com is on a distinguished road

      0  

    Default

    hm ok, thank you vietits

    Though why does the docs give this
    Code:
    Ext.define('MyApp.app.Application', {
        extend: 'Ext.app.Application',
        ...
    });
     Ext.application({
        extend: 'MyApp.app.Application',
    
        name: 'Blog',
        models: ['Post', 'Comment'],
        controllers: ['Posts', 'Comments'],
    
        launch: function() {
            ...
        }
    });
    as an example for extending Ext.app.Application? Most of the times I look at the docs, the given examples don't work. This is not a quality mark.

  5. #4
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Vote Rating
    112
    Answers
    347
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default

    What Ext version do you use? The document on the web is for 4.1.3. Maybe this is applied for Ext 4.1.2 or Ext 4.1.3 but this is not applied for Ext 4.1.1a or earlier.

  6. #5
    Sencha User
    Join Date
    Oct 2012
    Posts
    3
    Vote Rating
    0
    schmidt@archomedia.com is on a distinguished road

      0  

    Default

    this could be the reason, I'm using 4.1.1. Is there a doc especially for 4.1.1?

  7. #6
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Vote Rating
    112
    Answers
    347
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default

    If you downloaded and unziped Ext 4.1.1, then the documents is under "docs" folder.

Thread Participants: 1