摘自:http://www.darronschall.com/weblog/archives/000135.cfm
//复制OnRowPress,重写OnRowPress
///////////////////////////////////////////////////////////////////////////
// Double-Click Hack for List-based components
// Nov. 15, 2004 - Darron Schall
// create quick reference to ScrollSelectList's prototype
var sslp = _global.mx.controls.listclasses.ScrollSelectList.prototype;
// only run this code once.., make sure that $ oldOnRowPress is not
// defined to avoid inifinite recursion when onRowPress is called
if (!sslp.$ oldOnRowPress) {
sslp.DOUBLE_CLICK_INTERVAL = 300; // in milliseconds, how close two clicks must
// be received to register as a double click
// save a reference to the onRowPress function since we need to overwrite it to add
// functionality, and we don't want to lose the original.
sslp.$ oldOnRowPress = sslp.onRowPress;
// add doubleClick event to the ScrollSelectList class
sslp.onRowPress = function(rowIndex) {
// if the user pressed the samw row within the time limit, fire off
if (getTimer() - this.lastPressedTime < this.DOUBLE_CLICK_INTERVAL && this.lastPressedRow == rowIndex) {
this.dispatchEvent({target:this,type:"doubleClick",row:rowIndex});
} else {
// not a double click - record their click time and the row selected to prepare
// for double click
// only allow double clicks under the proper conditions
if (this.enabled && this.selectable) {
this.lastPressedTime = getTimer();
this.lastPressedRow = rowIndex;
} else {
// not really necessary, but just in case.. make sure
// doubleClick doesn't accidentally fire
this.lastPressedTime = 0;
this.lastPressedRow = -1;
}
// invoke the old method that we just overwrote - using apply to get the scope correct
this.$ oldOnRowPress.apply(this, [rowIndex]);
}
};
}
delete sslp;
list.dataProvider = [{label:"test"},{label:"test2"},{label:"test3"}];
list.addEventListener("doubleClick", mx.utils.Delegate.create(this, onItemSelected));
function onItemSelected(eventObj) {
// do something with the selected item
trace(eventObj.row);
//trace(sslp.onRowPress)
}
回复Comments
作者:
{commentrecontent}