Results 1 to 10 of 11

Thread: Why doesn't 'Ext.Msg.alert(...)' work while 'Ext.Msg.prompt()' does?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Feb 2012
    Vote Rating

    Default Answered: Why doesn't 'Ext.Msg.alert(...)' work while 'Ext.Msg.prompt()' does?

    I'm just starting with Ext JS and trying to understand the why's of the following using Ext4.

    These work:
    Ext.Msg.prompt('...', '...', fn);{...});

    But this doesn't work in the latest Chrome and FF:
    Ext.Msg.alert('...', '...', fn);
    Chrome gives the console msg: Cannot call method 'alert' of undefined.

    So I'm using:
    Ext.create('Ext.window.MessageBox').alert('...', '...', fn);

  2. Thank you Chamacs.
    The following is my new noobie understanding. I'm most uncertain about the very last paragraph. Please correct me if I'm wrong. Thanks.

    I can use
    Ext.Msg.alert('...', '...', fn);

    (a) with the brute-force way using
    <script type="text/javascript" src="../../extjs/ext-all-debug.js"></script>
    or ext-all-dev.js or ext-all.js

    (b) with dynamic loading using
    <script type="text/javascript" src="../../extjs/ext-dev.js"></script>
    or ext-debug.js or ext.js
    <script type="text/javascript">
    // A leading script tag is used to ensure this is all loaded before
    // the following script starts executing.
        enabled        : true,
        disableCaching : false,
        paths          : {
            // relative path where to find '' thingies
            'Ext' : '../../extjs/src'
    // Do asynchronous loading of classes we know we'll need
    <script type="text/javascript">
    Ext.onReady(function () {
    // Following gives: TypeError: Obj fcn () {...} has no method alert
    // because 'Ext.window.MessageBox' is a class, while
    // 'Ext.MessageBox' is a singleton instance of it, while
    // 'Ext.Msg' is a convenience alternate name for 'Ext.MessageBox'
    //    Ext.window.MessageBox.alert('Hello.', 'The DOM is ready');
    // Following also work   
    //    Ext.Msg.alert('Hello.', 'The DOM is ready');
    //    Ext.MessageBox.alert('Hello.', 'The DOM is ready');
    // If Ext.require does not exist above, this synchronously loads the class on demand
    // If Ext.require exists above, Ext.Loader knows class is loaded already
        var win = Ext.create('Ext.window.MessageBox');
        win.alert('Hello.', 'The DOM is ready!'); 
    My main uncertainty: Ext.window.MessageBox is a class (implemented as a function) and so you cannot use .alert on it. Ext.MessageBox and Ext.Msg are the same singleton instance (implemented as an object) of the class (via 'new') and so .alert can be called on them.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts