『我闪网~www.5shan.com』

Categories

-=推荐开发方面的Flash新闻、教程、下载、酷站、游戏、图片等=-
首页

Links

New Comments

Counter

Calendar

[教程]为V2组件(list\tree\datagrid)增加双击事件

Author:我闪 PublishTime:2004-11-16

看到老外的一篇教程,还不错。推荐给大家,自己也做个记号。首先在第一桢输入:

// 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组件,命名为“list”

// drag v2 list component onto stage and name it "list"
// place above code on frame 1 followed by below code:

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("double click");
}

这样就OK了,继承list类的list\tree\datagrid组件均可实现双击~ ^-^

[From darron schall] 原文:http://www.darronschall.com/weblog/archives/000135.cfm

Comments

{CommentAuthor} at {CommentTime} | {CommentEmail} {CommentUrl} {CommentIp}
{CommentContent}
Powered by 5DBlog.com