// 文本框回车键检测 -------------------------------------------------------------------------------------------------------------- //TextField.onSubmit,用来模拟HTML中的按回车提交表单,deckar TextField.prototype.addSubmitHandler = function() { // listener to Key.onKeyDown event this.onKeyDown = function(s) { this.isFocused = eval(Selection.getFocus()) == this; if (this.isFocused && Key.getCode() == 13) { // Key.ENTER is pressed this.broadcastMessage("onSubmit", this); this.onSubmit(); } }; Key.addListener(this); return true; }; // 使用方法 1: onSubmit myTextField.onSubmit = function() { textfield2.text = myTextField.text; }; myTextField.addSubmitHandler(); // 使用方法 2: listener var submitListener = {onSubmit:function () { _root.backgroundMC.play(); }}; myTextField.addListener(submitListener); // 文本框内容滚动 -------------------------------------------------------------------------------------------------------------- //Simple scrolling system for text fields, up/down arrows appear on rollover. Works with AS1 AS2 SWF6 SWF7. TextField.prototype.activateScroll = function(color, alpha) { // exit if there are not enough lines to require scrolling) if (this.maxscroll == 1) { return; } // the only tricky part is choosing a level where the scrollerMc will be created. // this scroller is created on the parent of the textfield (we can not create clips inside a text field) // the name for this clip equals the textfields name with "_scrollerMc" appended at the end. // when using Player V7, remove the next "if" block and replace the "++textScrollerLevel" with "this._parent.getNextHighestDepth()" // if you need levels 99999 and up for something different, you should know how to replace "++textScrollerLevel" with your own function or variable if (textScrollerLevel == undefined) { _global.textScrollerLevel = 99999; } // create container with two buttons and two arrows var S = this._parent.createEmptyMovieClip(this._name+"_scrollerMc", ++textScrollerLevel); // locate it exactly where the textfield is S._x = this._x; S._y = this._y; // size for the buttons: full width, half height of the textfield var h = this._height/2; var w = this._width; // create both buttons now for (var i = 0; i<2; i++) { var but = S.createEmptyMovieClip("but"+i, i); // draw transparent button that covers top/bottom half of text field but.lineStyle(0, 0, 0); but.beginFill(0, 0); but.moveTo(0, 0); but.lineTo(w, 0); but.lineTo(w, h); but.lineTo(0, h); but.lineTo(0, 0); but.endFill(); // move second button down so they do not overlap but._y = i*h; // create arrow inside button var arrw = but.createEmptyMovieClip("arrw", 1); // draw arrow arrw.lineStyle(0, 0, 0); arrw.beginFill(color, alpha); arrw.moveTo(0, -h*0.3); arrw.lineTo(h*0.3, h*0.3); arrw.lineTo(-h*0.3, h*0.3); arrw.lineTo(0, -h*0.3); arrw.endFill(); // move arrow to center of button arrw._x = w/2; arrw._y = h/2; // rotate second arrow arrw._rotation = i*180; // make them invisible arrw._visible = false; // pointer to textfield but.target = this; // direction in which each button should scroll but.dir = i == 1 ? 1 : -1; // function that scrolls, will be called by timer but.doScroll = function() { this.target.scroll += this.dir; }; // when we press button, scroll + activate timer for further scrolling but.onPress = function() { this.doScroll(); this.timerId = setInterval(this, "doScroll", 100); }; // when releasing the button, deactivate timer but.onRelease = function() { clearInterval(this.timerId); }; but.onReleaseOutside = but.onRelease; // show arrow on rollover but.onRollOver = function() { this.arrw._visible = true; }; // hide arrow on roll out but.onRollOut = function() { this.arrw._visible = false; }; } }; TextField.prototype.deactivateScroll = function() { this._parent.textScrollerMc.removeMovieClip(); }; // --- Example begins sampletext = "It's not very beautiful, but you can adapt it to suit your own needs so you don't have to start from scratch.In this case I didn't need any tweening or smooth motion, just a very simple way of scrolling text.Works with AS1 AS2 SWF6 SWF7."; createTextField("txt", 1, 50, 50, 100, 100); txt.wordWrap = true; txt.text = sampletext; txt.activateScroll(0xFF0000, 15); // 打字效果 ------------------------------------------------------------------------------------------------------------------------------- TextField.prototype.flipTo = function(s, rot) { if (s == undefined) { s = ""; } if (this.text == "") { this.text = " "; } var T = this._parent.createEmptyMovieClip(this._name+"_typer", this._parent.getNextHighestDepth()); T.txt = s; T.rot = rot == undefined ? 0 : rot; T.targ = this; T.oldtxt = this.text; // find out how many chars back we have to go // (maybe the beginning of old and new word are the same) for (var i = 0; ithis.rot) { L = L+T.dir; this.count = 0; } // invents characters between 48 (0) and z (122) var rndchar = chr(48+Math.random()*74); if (this.dir<1) { if (L>T.backto) { this.targ.text = this.targ.text.substr(0, L-1)+rndchar; } else { this.dir = 1; } } else { if (L<=T.txt.length) { this.targ.text = this.txt.substr(0, L-1)+rndchar; } else { this.targ.text = this.txt; this.onEnterFrame = undefined; this.removeMovieClip(); } } }; }; // Example sampletext = "Saw this effect somewhere and I wanted to use it too.Easy to use, maybe not so easy to understand (no time for better code)."; createTextField("txt", 1, 50, 50, 120, 100); txt.wordWrap = true; txt.text = sampletext; txt.flipTo("Works with AS1 or AS2. getNextHighestDepth() needs Flash Player 7. (replace it with a number or a custom function for Player 6)."); /* Create a text field, give it a name (like my_txt) and use like this: my_txt.flipTo("N4476S N8068V"); To erase the content of the text field, use without parameters: my_txt.flipTo(); For a slower effect, use the second parameter specifying the number of rotations per character: my_txt.flipTo("slower", 5); Saw this effect somewhere and I wanted to use it too.Easy to use, maybe not so easy to understand (no time for better code).Works with AS1 or AS2. getNextHighestDepth() needs Flash Player 7. (replace it with a number or a custom function for Player 6). */ // URL地址转换成链接 ------------------------------------------------------------------------------------------------------------------------------- TextField.prototype.SelectURLs = function(txt) { var z = [" www.", " http://", " https://", " ftp://"]; for (var i1 in z) { while ((i=txt.indexOf(z[i1], last_i))>0) { j = txt.indexOf(" ", i+1); if (j<0) { j = txt.length; } j--; while (txt.charAt(j) == "." or txt.charAt(j) == ",") { j--; } j2 = txt.indexOf("]", i); if (j2>0) { j3 = txt.indexOf("[", i); if (j3>0) { if (j3>j2) { last_i = j; continue; } } else { last_i = j; continue; } } var url = txt.substring(i+1, j+1); if (url.indexOf("://")<0) { url = "http://"+url; } txt = txt.substr(0, i+1)+" "+""+url+""+txt.substr(j+1); last_i = i+34+url.length*2; } } this.htmlText = txt; }; // Example createTextField("news_txt", 1, 50, 50, 200, 20); news_txt.html = true; t = "text www.shaggysmile.com text"; news_txt.SelectURLs(t); // 返回文本框所使用的字体 ------------------------------------------------------------------------------------------------------------------------------- // font_map - property. returns an array of fonts used in the text field // ? Ivan Dembicki, dembicki@narod.ru setFontMapProperty=function () { var nextNode = function (nod) { if (nod.firstChild != null) {return nod.firstChild;}var n = nod;while (n.nextSibling == null) {if (n.parentNode) {n = n.parentNode;} else {return null;}}return n.nextSibling;}, textNodes = function (nod) { var arr = [];while (nod) {if (nod.nodeType == 3) {arr.push(nod);}nod = nextNode(nod);}return arr;}, getFace = function (n) { return n.attributes.FACE == undefined ? arguments.callee(n.parentNode) : n.attributes.FACE;}, getFontMap = function () { var back = (!this.html ? this.html=true : false);var arr = textNodes(new XML(this.htmlText));var len = arr.length, nod, n_obj = {}, n_arr = [], face, np, i;while (len--) {face = getFace(np=(nod=arr[len]).parentNode);if (np.nodeName == "I") {face += (np.parentNode.nodeName == "B" ? "_bold_italic" : "_italic");} else if (np.nodeName == "B") {face += "_bold";}n_obj[face] = face;}for (i in n_obj) {n_arr.push(n_obj[i]);}back ? this.html=false : "";return n_arr;}; TextField.prototype.addProperty("font_map", getFontMap, null), ASSetPropFlags(TextField.prototype, "font_map", 7, 1); }, setFontMapProperty(), delete setFontMapProperty; // Example createTextField("news_txt", 1, 50, 50, 200, 20); news_txt.text = "samstudio.collection"; trace(_root.news_txt.font_map); // 根据文本框长度自动裁剪文本并以省略号代替 ------------------------------------------------------------------------------------------------------------------------------- //------------------------------------------ //------------------------------------------ // ? Copyright 2003 hypergeneric media for the masses // questions? sab@hypergeneric.com // www.hypergeneric.com // this is a revision on http://proto.layer51.com/d.aspx?f=469 // i have simplified it because the other ones were getting out of control // this is just for singleline, non-wrapped text. it will auto-ellipsis if it needs it. // it saves cpu cycles by not doing the loop if unessessary //------------------------------------------ //------------------------------------------ //------------------------------------------ // begin class script //------------------------------------------ // add an ellipsis //------------------------------------------ TextField.prototype.ellipsis = function() { this.multiline = true; this.wordWrap = true; this.text = this.text; if (this.maxscroll>1) { var t = this.text; this.text = ""; for (var i=0; this.maxscroll<=1 and this.text != t; ++i) { this.text += t.substr(i,1); } this.text = t.substr(0,i-3)+"..."; } this.multiline = false; this.wordWrap = false; }; //------------------------------------------ // end prototype script //------------------------------------------ //will need ellipsis this.createTextField("mt1", 1, 100, 100, 100, 20); mt1.text = "012345678901234567890123456789"; mt1.ellipsis(); //will not need ellipsis this.createTextField("mt2", 2, 100, 200, 100, 20); mt2.text = "0123456789"; mt2.ellipsis(); // 字符间距设定 ------------------------------------------------------------------------------------------------------------------------------- TextField.prototype.kern = function(kern_size) { // init vars var temp = this.text; this.text = ""; var kernChar = new TextFormat(); kernChar.size = kern_size; // space out text for (var i = 0; i