PDA

View Full Version : Does 1.0 support createDelegate?



DaveC426913
24 Nov 2010, 9:46 AM
I am just upgrading to 1.0. The first error is

Object function scrollMe(listId,direction){...} has no method 'createDelegate'

I don't know if this is no longer supported (I do see references to it in the sencha-touch.js), or if it's just slightly incompatible with the way I implemented it when running Beta Sencha versions.

Trouble is, this createDelegate was a method that was gifted to me, so I don't really know how to debug it.



MERCON.UI.Component.scrollButtons = Ext.extend(Ext.Container, {
thisItem: this,
initComponent: function() {
var config = {
id: 'scroller',
cls: 'scroller',
items: [{
xtype: 'button',
handler: scrollMe.createDelegate(null, [this.MRC_panelid,-1], false),
cls: 'btnUp',
html: '<img src="img/glyph_up.png">',
},{
xtype: 'button',
handler: scrollMe.createDelegate(null, [this.MRC_panelid,1], false),
cls: 'btnDn',
html: '<img src="img/glyph_dn.png">',
}]
}
Ext.apply(this, Ext.apply(this.initialConfig, config));
MERCON.UI.Component.scrollButtons.superclass.initComponent.apply(this, arguments);

function scrollMe(listId,direction){
scrollingList = Ext.getCmp(listId);
var scroller = scrollingList.scroller,
offsets = scroller.getOffset();
lineHeight=25;//the height of one line of text - hardcoded for now
scrollAmt = (scrollingList.height-lineHeight)*direction;//
scroller.scrollTo( {x: offsets.x,y: offsets.y + scrollAmt}, true);
}
},

evant
24 Nov 2010, 12:08 PM
http://dev.sencha.com/deploy/dev/docs/?class=Ext.util.Functions&member=createDelegate

Steffen Hiller
24 Nov 2010, 12:10 PM
You have to use Ext.util.Functions.createDelegate(function, ...) starting in 1.0.

DaveC426913
24 Nov 2010, 12:11 PM
You have to use Ext.util.Functions.createDelegate(function, ...) starting in 1.0.

Oh, so it's just the extended reference and syntax when I'm calling it. Thanks.

DaveC426913
25 Nov 2010, 7:13 AM
http://dev.sencha.com/deploy/dev/docs/?class=Ext.util.Functions&member=createDelegate

Sorry, the example doesn't match my current button implementation. I don't see how I'm supposed to implement it.

This is what I'm trying to do:


initComponent: function() {
var config = {
xtype: 'button',
handler: Ext.Function.createDelegate(scroll, 1) ,
}
},

scroll: function(dir){
...
scrollAmt = (scrollingTextPanel.height-lineHeight)*dir;//
...
},



Actually, there's a simpler way than createDelegate for what I'm trying to do.

All I'm trying to do is have one function, called by two buttons. Each button passes a parameter.

This is what I did:



items: [{
xtype: 'button',
handler: this.scroll,
MRC_dir: -1,
},{
xtype: 'button',
handler: this.scroll,
MRC_dir: 1,
}]

scroll: function(button){
...
scrollAmt = (scrollingTextPanel.height-lineHeight)*button.MRC_dir;//
...
},

evant
25 Nov 2010, 11:58 AM
The args changed, to accommodate the move to a function, so:



Ext.createDelegate(fn, null, [1]);

DaveC426913
25 Nov 2010, 12:00 PM
The args changed, to accommodate the move to a function, so:



Ext.createDelegate(fn, null, [1]);


Ah. I should probably use that rather than my 'MRC_dir' method. Thx.

evant
25 Nov 2010, 12:08 PM
Either/or. Yours works well, it's a pretty neat solution.