-
24 Jan 2012 6:48 AM #1
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:
The result is that the handler of button1 doesn't work, the handler of button2 works fine. What I'm doing wrong?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}] } ] }); } });
Both handlers work fine for me with ST1.x, but not with ST2...
Thx for your help!
-
Best Answer Posted by mitchellsimoens
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.
-
24 Jan 2012 9:03 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,641
- Vote Rating
- 434
- Answers
- 3107
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
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
26 Jan 2012 3:17 AM #3
Thanks Mitchell, I appreciate your help...
-
26 Jan 2012 6:46 AM #4
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:
The result is, that the panels are displayed, but buttons or togglefields don't work anymore.Code:var aName = Ext.create('Ext.Panel',{...)
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":
Then I have just to add one line into my launch function, for example:Code:Ext.define('AName',{extend: 'Ext.Panel', config: { - orginal Panel config - }});
Is this a good idea or are there better ways?Code:var aName = Ext.create('AName', {});
Thx again for your help...


Reply With Quote