PDA

View Full Version : Schedule method call with setTimeout



luca.santaniello
7 Sep 2010, 1:16 AM
Hi,

I want to simulate setTimeout() function. it receives global function name. I must pass to setTimeout my method name of Ext object...

Example:



RefreshLayersComponent = Ext.extend(Ext.FormPanel,
{
id: 'RefreshLayersComponent',

constructor: function(config)
{
...
...
},

afterRender: function()
{
RefreshLayersComponent.superclass.afterRender.apply(this, arguments);

this.autoRefresh();
},

refresh: function()
{
...
...
},

autoRefresh: function()
{
this.refresh();
setTimeout("this.autoRefresh()", 3000);
}
});


setTimeout("this.autoRefresh()", 3000); run first time but then it generate error...

Error is: this.autoRefresh is not a function

Can you help me please?

Thanks in advance

Luca

Condor
7 Sep 2010, 1:19 AM
That is because setTimeout executes in the 'window' scope.

You want:

Ext.TaskMgr.start({
run: this.refresh,
scope: this,
interval: 3000
});

hieu79vn
23 Sep 2012, 10:45 PM
Hi,

I tried to catch the onclose event of popup by Ext.TaskManager but i doesnt run. Could you tell me what is the problem in my code?
Thank you

createEditor: function(){
this.editor = Ext.create('widget.texteditor',{
height: 200
});
var toolbar = this.editor.getToolbar();
toolbar.add({
iconCls: 'icon-attachment',
scope: this,
handler: function() {
var myWindow = window.open('<%=PopupUrl(.....................');
this.pollForWindowClosure(myWindow);
}
});
return this.editor;
},
pollForWindowClosure: function(myWindow){
if (myWindow.closed){
this.myFunc();
return;
}
//setTimeout(function(){this.pollForWindowClosure(myWindow)}, 10);
Ext.TaskManager.start({
//run: this.refresh,
run: function(){this.pollForWindowClosure(myWindow)},
scope: this,
interval: 10
});
},
myFunc: function(){
alert('789');
},