📄 smiletext.as
字号:
#initclip 10_global.SmileText = function() { //first init all variables //************************************************* //maximum number of messages in smile text. this.maxMessageCount = 100; //current number of messages in smile text. this.messageCount = 0; //do realignment of smiles or do not do this.isRefresh = false; this.isColored = true; this.selfColor = -1; //text format initials options this.tf_font = _level0.ini.text.itemToChange.mainChat.fontFamily; this.tf_size = _level0.ini.text.itemToChange.mainChat.fontSize; this.showSmilies = _level0.ini.layout.toolbar.smilies; this.textFormat = new TextFormat(this.tf_font , this.tf_size); //objects depth this.curDepth = 10; //setInterval ID _global.FlashChatNS['SmileInitId_' + this._name] = null; this.width = undefined; this.height = undefined; this.min_width = 60; //************************************************* //create objects this.createTextField("smile_txt", this.curDepth++, 0, 0, 100, 100); this.createTextField("test_txt", this.curDepth++, 0, 250, 100, 100); this.setTextFieldProp(this.smile_txt,{ background:false, wordWrap:!this.showSmilies, multiline:true, border:false, html:true}); this.setTextFieldProp(this.test_txt,{_visible:false, background:false, wordWrap:!this.showSmilies, multiline:true, border:true, html:true}); //this function is called when mouse wheel is. this.smile_txt.mouseWheelEnabled = false; //this function is called each time 'scroll' property of smile_txt changes. //depending on whether mouse is down and whether some text is selected //it shows or hides icons. this.smile_txt.onScroller = this.onScrollerSmile; //number of text lines visible in text field. this.addProperty('_width', this.getPropWidth, this.setPropWidth); this.addProperty('_height', this.getPropHeight, this.setPropHeight); //--- //create border this.createEmptyMovieClip(this._name + '_border', this.curDepth++); this.border = this[this._name + '_border']; //create container that keeps all icons. this.createEmptyMovieClip(this._name + '_iconContainer', this.curDepth++); this.iconContainer = this[this._name + '_iconContainer']; //create vertical scroll bar this.attachMovie("FScrollBarSymbol", "scrollBar", this.curDepth++); this.scrollBar.setScrollTarget(this.smile_txt); this.scrollBar.autoHide = true; //create mask. this.createEmptyMovieClip(this._name + '_mask', this.curDepth++, {_x : -1, _y : -1}); this.mask = this[this._name + '_mask']; this.mask.drawRect2(0, 0, 1, 1, 0.1, 0x000000, 100, 0x000000, 100); this.mask._visible = false; this.setMask(this.mask); //align in first time all objects this._xscale = 100; this._yscale = 100; this.setSize(100, 100); //-------------------------------------------------------------------------------- if( this.showSmilies ) { //main smile property hash table this._SMI = new Object(); for(var i=0; i < SmileTextConst.patternList.length; i++) { var smile_name = SmileTextConst.patternList[i][0]; this._SMI[smile_name] = new Object(); this._SMI[smile_name]["id"] = i; this._SMI[smile_name]["link"] = SmileTextConst.patternList[i][1]; this._SMI[smile_name]["width"] = _global.FlashChatNS.SMILIES[SmileTextConst.patternList[i][1]].width; this._SMI[smile_name]["height"] = _global.FlashChatNS.SMILIES[SmileTextConst.patternList[i][1]].height; this._SMI[smile_name]["space_width"] = this._SMI[smile_name]["width"]; } } this.smile_txt.htmlText = ""; this.setupTextFormat(); //messages array this.messages = new Array(); this.smile_counter = 0; };_global.SmileText.prototype = new MovieClip();//CONSTANTS._global.SmileText.prototype.backgroundColor = 0xffffff;_global.SmileText.prototype.borderColor = 0x000000;//-------------------------------------------------------------//_global.SmileText.prototype.BREAK = 1; //'br';_global.SmileText.prototype.TMP_BREAK = 2; //'tb';_global.SmileText.prototype.WORD = 3; //'w';_global.SmileText.prototype.SMILE = 4; //'s';_global.SmileText.prototype.TAG = 5; //'t';//-------------------------------------------------------------//_global.SmileText.prototype.SP = ' ';_global.SmileText.prototype.BR = '<br>';//-------------------------------------------------------------////private metod_global.SmileText.prototype.setTextFieldProp = function(_txt, _prop){ for(var p in _prop) { _txt[p] = _prop[p]; } }//---_global.SmileText.prototype.setFont = function(inFontProp, propName){ if(propName == 'font') this.setupTextFormat(inFontProp, this.tf_size); else if(propName == 'size') this.setupTextFormat(this.tf_font, inFontProp); this.setupTextFormat(this.tf_font, this.tf_size); this.isRefresh = true; //this.AlignSmilies(); //this.refreshText(); clearInterval(_global.FlashChatNS['SmileInitId_' + this._name]); _global.FlashChatNS['SmileInitId_' + this._name] = setInterval(this, 'setFontAlignSmilies', 1);}_global.SmileText.prototype.setFontAlignSmilies = function(){ clearInterval(_global.FlashChatNS['SmileInitId_' + this._name]); this.AlignSmilies(); _global.FlashChatNS['SmileInitId_' + this._name] = setInterval(this, 'setFontRefreshText', 1);}_global.SmileText.prototype.setFontRefreshText = function(){ clearInterval(_global.FlashChatNS['SmileInitId_' + this._name]); this.refreshText(); this.setMaxScroll(); this.onEnterFrame = this.updateScroll;}_global.SmileText.prototype.setColored = function(inColor, inVal){ this.selfColor = (inColor != undefined)? inColor : this.selfColor; if(this.isColored == inVal) return; this.isColored = (inVal != undefined)? inVal : this.isColored; //refresh text this.smile_txt.htmlText = ""; for(var i = 0; i < this.messages.length; i++) { var msg_obj = this.messages[i]; var msg = (this.showSmilies)? msg_obj.sequence.data.join('') : msg_obj.msg; msg_obj.color = (this.isColored)? msg_obj.realcolor : this.selfColor; this.appendMessage(this.smile_txt, msg, msg_obj.color, false); } this.onEnterFrame = this.updateScroll;}_global.SmileText.prototype.smile2font = function(inIco, x_y, dY, ico_name){ this.smileSetSize(inIco, ico_name); inIco._x = x_y.x + (this._SMI[ico_name]["spaces_width"] - inIco.width)/2; inIco.y = x_y.y + dY; dY -= (this.smile_txt.scroll-1) * this.textFieldHeight; inIco._y = x_y.y + dY; return (inIco);}_global.SmileText.prototype.smileSetSize = function(inIco, ico_name){ if(this.tf_size != inIco.width) { var w2h = this._SMI[ico_name]['width'] / this._SMI[ico_name]['height']; if(inIco.width == undefined) { inIco._yscale = (this.tf_size / this._SMI[ico_name]['height']) * inIco._yscale; inIco._xscale = ((this.tf_size * w2h) / this._SMI[ico_name]['width']) * inIco._xscale; } else { inIco._yscale = (this.tf_size / inIco.height) * inIco._yscale; inIco._xscale = ((this.tf_size * w2h) / inIco.width) * inIco._xscale; } inIco.width = this._SMI[ico_name]['width']*inIco._xscale/100; inIco.height = this._SMI[ico_name]['height']*inIco._yscale/100; this._SMI[ico_name]["space_width"] = inIco.width; }}_global.SmileText.prototype.onScrollerSmile = function(text_field){ var p = this._parent; var dY = -(text_field.scroll - 1) * p.textFieldHeight; for(var i=1; i<=p.smile_counter; i++) { var ico = p.iconContainer["ico"+i]; ico._y = ico.y + dY; p.showSmile(ico); var nY = ico.y + dY; //trace('nY ' + nY + ' < 0 ? : > ' + (p.height - p.textFieldHeight) + ' ? : dummi ' + ico.dummi); /* var not_on_scr = nY < 0 || nY > (p.height - p.textFieldHeight); if( not_on_scr ) //remove unvisible smile { if( !ico.dummi ) { var dummi = new Object({ link : ico.link, msgId : ico.msgId, icoId : ico.icoId, depth : ico.getDepth(), y : ico.y, dummi : true, _name : ico._name, _visible : ico._visible, _x : ico._x, _y : ico._y, _xscale : ico._xscale, _yscale : ico._yscale, width : ico.width, height : ico.height }); ico.removeMovieClip(); p.iconContainer["ico"+i] = dummi; //trace('DELETE SMILE'); //dbg(dummi); var msg = p.messages[dummi.msgId]; msg.smiles[dummi.icoId]["ico"] = p.iconContainer["ico"+i]; } } else if( ico.dummi ) //attach smile again { ico.dummi = false; p.iconContainer["ico"+i] = p.iconContainer.attachMovie( ico.link, ico._name, ico.depth, ico ); //trace('CREATE SMILE'); //dbg(ico); var msg = p.messages[ico.msgId]; msg.smiles[ico.icoId]["ico"] = p.iconContainer["ico"+i]; } */ //checking system }}//PUBLIC METHODS._global.SmileText.prototype.setShowSmilies = function(inVal) { this.showSmilies = inVal; this.smile_txt.wordWrap = !inVal; this.test_txt.wordWrap = !inVal;}_global.SmileText.prototype.addText = function(lbl, msg, inColor, inUserId) { if(msg == undefined || msg == "") return; this.scrollPosition = (this.smile_txt.scroll == this.smile_txt.maxscroll)? true : false; //remove top messages if need if( this.messages.length >= this.maxMessageCount) { //remove smilies for(var i = 0; i < (this.maxMessageCount / 3) - 1; i++) { var msg_obj = this.messages[i]; for(var j = 0; j < msg_obj.smiles.length; j++) { msg_obj.smiles[j]["ico"].removeMovieClip(); delete(msg_obj.smiles[j]["ico"]); } } this.messages.splice(0, this.maxMessageCount / 3); this.refreshText(); } var msg_obj = new Object(); var lbl_msg = ''; if(inUserId != null) { //apply label format var parent = _global.FlashChatNS.chatUI; var sender = parent.getUser(inUserId); lbl_msg = this.str_replace(lbl, "AVATAR", sender.getAvatar('mainchat')); } msg_obj.label= lbl; msg_obj.text = msg; msg_obj.msg = lbl_msg + replaceHTMLSpecChars( msg ); msg_obj.realcolor = inColor; msg_obj.color = (this.isColored || this.selfColor == -1)? inColor : this.selfColor; msg_obj.userId = inUserId; if(!this.showSmilies) { this.messages.push(msg_obj); this.appendMessage(this.smile_txt, msg_obj.msg, msg_obj.color, false); this.setMaxScroll(); this.onEnterFrame = this.updateScroll; return; } msg_obj.sequence = new Object(); msg_obj.sequence.label = new Array(); msg_obj.sequence.data = new Array(); msg_obj.sequence.br_index = new Array(); //parse message msg_obj.smiles = this.getSmilesInText( msg_obj.msg, sender.getAvatar('mainchat')); this.messages.push(msg_obj); this.addMessageToField(); this.setMaxScroll();};//---_global.SmileText.prototype.setMaxScroll = function(){ if(this.scrollPosition) this.smile_txt.scroll = 10000;}//---_global.SmileText.prototype.breakMessage = function(inArrObj){ inArrObj.label.push(this.TMP_BREAK); inArrObj.data.push(this.BR); inArrObj.br_index.push(inArrObj.label.length-1); //trace('LENGTH ' + inArrObj.label.length); var msg = '', otag = '', ctag = ''; for(var i = 0; i < inArrObj.label.length; i++) { var stype = inArrObj.label[i]; var sdata = inArrObj.data[i]; if(stype == this.TAG) { if(sdata.length < 5) { var upper = sdata.toUpperCase(); if(upper == '<B>' || upper == '<I>') { otag += sdata; ctag += sdata.charAt(0) + '/' + sdata.substr(1); } else if(upper == '</B>' || upper == '</I>') { otag = ctag = ''; } msg += sdata; } continue; } if(stype == this.BREAK) { msg = otag; continue; } msg += sdata; this.appendMessage(this.test_txt, msg + ctag, 0, true); if(this.test_txt.textWidth > (this.test_txt._width - 5)) { inArrObj.label.splice(i, 0, this.TMP_BREAK); inArrObj.data.splice(i, 0, this.BR); inArrObj.br_index.push(i); msg = otag; } } //trace('<BRAKE MESSAGE>'); //trace('label: ' + inArrObj.label); //trace('data : ' + inArrObj.data); return (inArrObj.data.join(''));}//---_global.SmileText.prototype.searchTags = function(inTxt){ var retObj = new Object(); retObj.label = new Array(); retObj.data = new Array(); var b = inTxt.split('<'); for(var i = 0; i < b.length; i++) { if(i == 0) { retObj.label.push(this.WORD); retObj.data.push(b[i]); continue; } var tag = '<' + b[i].substr(0, b[i].indexOf('>') + 1); var txt = b[i].substr(b[i].indexOf('>') + 1); if(tag.length > 2) { var n = (tag == this.BR)? this.BREAK : this.TAG; retObj.label.push(n); retObj.data.push(tag); } if(txt.length != 0) { retObj.label.push(this.WORD); retObj.data.push(txt); } } //trace('<SEARCH TAGS>'); //trace('ret l ' + retObj.label); //trace('ret d ' + retObj.data); return (retObj);}_global.SmileText.prototype.getWords = function(msg_obj, inTxt){ if(inTxt.length != 0) { //break tags var ret = this.searchTags(inTxt); for(var itm = 0; itm < ret.label.length; itm++) { var stype = ret.label[itm]; var sdata = ret.data[itm]; if(stype == this.BREAK || stype == this.TAG) { msg_obj.sequence.label.push(stype); msg_obj.sequence.data.push(sdata); } else if(stype == this.WORD) { var word = sdata.substr(0, sdata.indexOf(this.SP)); for(var i = word.length; i < sdata.length; i++) { var next_char = sdata.charAt(i); if(next_char != this.SP && (i != sdata.length-1)) word += next_char; else { if(i == sdata.length-1) word += next_char; else { for(var j = 1; next_char == this.SP && (i+j) < sdata.length; j++) { word += next_char; next_char = sdata.charAt(i+j); } i += (j-2); } //break big word if needed
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -