1. #1
    Sencha User
    Join Date
    Sep 2011
    Posts
    9
    Vote Rating
    0
    sencha_san is on a distinguished road

      0  

    Default Custom events

    Custom events


    Hi all,
    I'm new to sencha world ,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
    Santosh

  2. #2
    Sencha - Senior Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,997
    Vote Rating
    978
    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


    Code:
    Ext.define('My.Container', {
        extend : 'Ext.Container',
        xtype : 'mycontainer',
    
        initialize : function() {
            this.callParent(arguments);
    
            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) {
                console.log(arguments);
            }
        }
    });
    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:

    Code:
    this.fireEvent('customevent', this, var1, var2);
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Software Engineer
    ________________
    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.

  3. #3
    Sencha User
    Join Date
    Sep 2011
    Posts
    9
    Vote Rating
    0
    sencha_san is on a distinguished road

      0  

    Default thanks mitchell,it worked but...

    thanks mitchell,it worked but...


    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
    Santosh

  4. #4
    Sencha - Senior Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,997
    Vote Rating
    978
    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


    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.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Software Engineer
    ________________
    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.

  5. #5
    Ext JS Premium Member
    Join Date
    Apr 2010
    Location
    Omaha, NE
    Posts
    579
    Vote Rating
    30
    estesbubba has a spectacular aura about estesbubba has a spectacular aura about

      0  

    Default


    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:

    http://www.sencha.com/forum/showthre...om-controllerA

Thread Participants: 2

Tags for this Thread