1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    2
    Vote Rating
    0
    Prasath.msc@gmail.com is on a distinguished road

      0  

    Default Unanswered: Need to add touchstart and touchend event for button?

    Unanswered: Need to add touchstart and touchend event for button?


    Could you please tell me how to add touchstart event for a button in sencha touch 1.1.
    Ref:
    In the thread
    http://www.sencha.com/forum/showthre...896#post878896 it says that add the event in element.
    For me, element attribute showing as undefined for a button, in sencha 1.1 docs element definition for button is also not available.

    Could you please tell me how to use this ?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,582
    Vote Rating
    433
    Answers
    3102
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    That thread is in the ST2 forums and things don't work the same. Here is one way you can do it but you don't really have access to the button instance there:

    Code:
    new Ext.Button({
        text       : 'Test',
        listeners  : {
            el : {
                touchstart : function () {
                    console.log('touch start');
                    console.log(this); //of element
                },
                touchend : function() {
                    console.log('touch end');
                    console.log(this); //of element
                }
            }
        }
    });
    I would extend Button to do this:

    Code:
    Ext.ns('Ux');
    
    Ux.Button = Ext.extend(Ext.Button, {
        initEvents : function () {
            var me = this;
    
            me.mon(me.el, {
                scope : me,
    
                touchstart : me.onTouchStart,
                touchend   : me.onTouchEnd
            });
        },
    
        onTouchStart : function (e) {
            this.fireEvent('touchstart', this, e);
        },
    
        onTouchEnd : function (e) {
            this.fireEvent('touchend', this, e);
        }
    });
    
    Ext.reg('ux-button', Ux.Button);
    And then you have a touchstart and touchend event on the component:

    Code:
    new Ux.Button({
        text       : 'Test',
        listeners  : {
            touchstart : function (btn, e) {
                console.log('touch start');
                console.log(this); //of button
            },
            touchend : function(btn, e) {
                console.log('touch end');
                console.log(this); //of button
            }
        }
    });
    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.