聊天室客户端限制历史记录数的方法

来源:互联网 发布:买车软件 编辑:程序博客网 时间:2024/05/16 12:34
聊天室客户端限制历史记录数的方法

有时候,客户端历史记录不断的增加,会导致Flash运行和反应的迟钝,可以通过限制历史记录数的方法改善。
在客户端的chat组件代码中找到receiveMessage方法,使用下面的代码替换

1 : FCChatClass.prototype.receiveMessage = function( mesg ) {
2 : //this.history_txt.htmlText += mesg; 这行是原先的实现代码
3 : this.history.push(mesg);
4 : if (this.history.length>30) this.history.shift();
5 : this.history_txt.htmlText = this.history.join("");
6 : this.history_txt.scroll = this.history_txt.maxscroll;
7 : }

其中限制记录数可以自己调整,这里设为30。
在FCChatClass.prototype.init方法中定义history数组来保存本地聊天记录信息
1 : this.history = new Array();

还有一个地方要注意,在清空历史时候,也要把本地聊天记录数组清空:
1 : this.history.splice(0);

原创粉丝点击