1. #1
    Sencha User armode's Avatar
    Join Date
    Nov 2011
    Location
    Germany / Darmstadt
    Posts
    64
    Vote Rating
    4
    armode is on a distinguished road

      0  

    Default Answered: Button handler doesn't work if added inside a button variable

    Answered: Button handler doesn't work if added inside a button variable


    Hey,

    I have a problem adding a simple handler function to a button, if the button is stored in a variable...
    Here's a simple test case created with senchafiddle:
    Code:
    var han = function(btn, evt)
        {
            alert("Button tapped.");
        };
    
    var button1 = Ext.create('Ext.Button',
                             {
                                 text: 'button1',
                                 handler: han
                             });
    
    Ext.application({
        name: 'SenchaFiddle',
        launch: function() {
            Ext.create('Ext.Panel', {
                fullscreen: true,
                items: [
                    {
                        xtype  : 'toolbar',
                        height: '100%',
                        docked : 'top',
                        defaults: {width: 100, margin: 5},
                        items: [button1, {xtype: 'button', text: 'button2',  handler: han}]
                    }
                ]
            });
        }
    });
    The result is that the handler of button1 doesn't work, the handler of button2 works fine. What I'm doing wrong?
    Both handlers work fine for me with ST1.x, but not with ST2...
    Thx for your help!

  2. You should not instantiate a component outside Ext.setup or Ext.application like that. If you do the Ext.create within the launch method, everything will work.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,801
    Answers
    3467
    Vote Rating
    834
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You should not instantiate a component outside Ext.setup or Ext.application like that. If you do the Ext.create within the launch method, everything will work.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User armode's Avatar
    Join Date
    Nov 2011
    Location
    Germany / Darmstadt
    Posts
    64
    Vote Rating
    4
    armode is on a distinguished road

      0  

    Default


    Thanks Mitchell, I appreciate your help...

  5. #4
    Sencha User armode's Avatar
    Join Date
    Nov 2011
    Location
    Germany / Darmstadt
    Posts
    64
    Vote Rating
    4
    armode is on a distinguished road

      0  

    Default


    Ok, I'm running into simular problems, because my app has many JS files where all components are created outside the launch function in variables, like this:
    Code:
    var aName = Ext.create('Ext.Panel',{...)
    The result is, that the panels are displayed, but buttons or togglefields don't work anymore.

    I don't want to put all my components into the launch function and have one big file... Another solution is to create classes instead of my "global varibles":
    Code:
    Ext.define('AName',{
    extend: 'Ext.Panel', config: { - orginal Panel config - }
    });
    Then I have just to add one line into my launch function, for example:
    Code:
    var aName = Ext.create('AName', {});
    Is this a good idea or are there better ways?
    Thx again for your help...

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi