View Full Version : Custom events

4 Jan 2012, 8:53 PM
Hi all,
I'm new to sencha world :s,presently started working on Sencha Touch 2. Can someone explain how to register and fire custom events in ST2. I had hard time to run an example,googling the blogs etc.

Thanks in advance

5 Jan 2012, 7:50 AM
Ext.define('My.Container', {
extend : 'Ext.Container',
xtype : 'mycontainer',

initialize : function() {

this.on('painted', 'checkSomething', this, { single : true });

checkSomething : function(cmp) {
//do some stuff here

this.fireEvent('customevent', this);

Ext.create('My.Container', {
fullscreen : true,
listeners : {
customevent : function(cmp) {

The important part here is the line in red using fireEvent. To add more arguments to the event, you just add more to the fireEvent:

this.fireEvent('customevent', this, var1, var2);

5 Jan 2012, 8:43 PM
Thanks for your quick reply Mitchell, it worked perfectly. In the above example, "customevent" is fired when container is painted. Here what is "painted"?. how we are able to map "painted" to "customevent" ?

Thanks in advance

6 Jan 2012, 6:40 AM
painted in an event bubbled up from the element on the component and fired on the component when it is painted in the DOM. That's not what is important here, the important part is the fireEvent.

6 Jan 2012, 7:42 AM
As your application grows you'll probably want to fire events between controllers which is a little different. Here is how we are doing that: