PDA

View Full Version : Firing Event from App.js and execute it in controller in sencha touch 2



prudvi
23 Apr 2012, 2:10 AM
Hi,
Does any one knows how to fire event from app.js file of our application. i know firing events from views and executing those events using refs and controls. but i need to know how can we fire and execute events from app.js to controller. It would be better if any one posts the detailed logic...

pepperseb
24 Apr 2012, 2:46 AM
Ext.application({
name: 'MyApp',
launch: function() {
Ext.Ajax.request({ url: '/sessions', scope: this, success: function() {
//some code to construct the viewport
Ext.Viewport.add({...});

//your controllers can listen to this event
this.fireEvent('authenticated', this);
}
})
}
});
Ext.define('MyApp.controller.SomeController', {
extend: 'Ext.app.Controller', init: function() {
this.getApplication().on('authenticated', function() {
console.log('do something with the viewport');
}, this);
}
});
This example is taken from http://www.sencha.com/forum/showthread.php?197998-Strange-behavior-launch-process&p=786974#post786974

Hope it helps,
Pepperseb