Sencha Touch – Events


Sencha Touch – Events


”;


Events are something which get fired when something happens to the class. For example, when a button is getting clicked or before/after an element is rendered.

Methods of Writing Events

Following are the methods of writing events.

  • Built-in events using listeners.
  • Attaching events later
  • Custom events

Built-in Events Using Listeners

Sencha Touch provides listener property for writing events and custom events in Sencha Touch files.

Writing listener in Sencha Touch

We will add the listener in the previous program itself by adding listen property to the panel, shown as follows −

<!DOCTYPE html>
<html>
   <head>
      <link href = "https://cdn.sencha.com/touch/sencha-touch-2.4.2/resources/css/sencha-touch.css" rel = "stylesheet" />
      <script type = "text/javascript" src = "https://cdn.sencha.com/touch/sencha-touch-2.4.2/sencha-touch-all.js"></script>
      <script type = "text/javascript">
         Ext.application({
            name: ''Sencha'', launch: function() {
               Ext.create(''Ext.Panel'', {
                  html: ''My Panel'', fullscreen: true, listeners: {
                     painted: function() {
                        Ext.Msg.alert(''I was painted to the screen'');
                     }
                  }
               });
            }
         });
      </script> 
   </head>
</html>

This will produce following result −