TextField.prototype.constructTextbyLetter = function(txt, speed, size) { if (!size) { size = 1; } if (!speed) { speed = 10; } var i = 0; var txt = txt; clearInterval(_root[this._name+'Int']); _root[this._name+'Int'] = setInterval(function (_txt) { // from start //_txt.text = txt.substr(0, (i+=size)) // from start with acceleration _txt.text = txt.substr(0, _txt.length+(i += size)); // from end //_txt.text = txt.substr(txt.length-(i+=size)) // from end with acceleration //var first_letter = txt.length-(_txt.length+(i+=size)) //_txt.text = txt.substr((first_letter < 0 ? 0 : first_letter)) // updateAfterEvent(); if (_txt.length>=txt.length) { clearInterval(_root[_txt._name+'Int']); } }, speed, this); }; TextField.prototype.deConstructTextbyLetter = function(speed, size) { if (!size) { size = 1; } if (!speed) { speed = 10; } var i = 0; var len = this.length; clearInterval(_root[this._name+'Int']); _root[this._name+'Int'] = setInterval(function (_txt) { // from end //_txt.text = _txt.text.substr(0, len-(i+=size)) // from end with acceleration //_txt.text = _txt.text.substr(0, _txt.length-(i+=size)) // from start //_txt.text = _txt.text.substr(size) // from start with acceleration _txt.text = _txt.text.substr((i += size)); updateAfterEvent(); if (!_txt.length) { clearInterval(_root[_txt._name+'Int']); } }, speed, this); };
Usage:
//Create a textfield in the main timeline, name it to test, make it dynamic. //put this code to your _root. test.constructTextbyLetter("Another sample text .", 100, 3); // or test.constructTextbyLetter("Another sample text .", 100); //Deconstruct: test.constructTextbyLetter(100);













我發現你的代碼有錯誤,應該是這樣子的。哈哈
TextField.prototype.constructTextbyLetter = function (txt, speed, size)
{
var _l1 = speed;
var _l2 = this;
var _l3 = _root;
if (!size)
{
size = 1;
} // end if
if (!_l1)
{
_l1 = 10;
} // end if
var i = 0;
var txt = txt;
clearInterval(_l3[_l2._name "Int"]);
_l3[_l2._name "Int"] = setInterval(function (_txt)
{
var _l1 = _txt;
_l1.text = txt.substr(0, _l1.length (i = i size));
updateAfterEvent();
if (_l1.length >= txt.length)
{
clearInterval(_root[_l1._name "Int"]);
} // end if
}, _l1, _l2);
};
TextField.prototype.deConstructTextbyLetter = function (speed, size)
{
var _l1 = this;
var _l2 = speed;
var _l3 = _root;
if (!size)
{
size = 1;
} // end if
if (!_l2)
{
_l2 = 10;
} // end if
var i = 0;
var len = _l1.length;
clearInterval(_l3[_l1._name "Int"]);
_l3[_l1._name "Int"] = setInterval(function (_txt)
{
var _l1 = _txt;
_l1.text = _l1.text.substr(i = i size);
updateAfterEvent();
if (!_l1.length)
{
clearInterval(_root[_l1._name "Int"]);
} // end if
}, _l2, _l1);
};
tu tworze pole textowe
createTextField(“movingField_txt”, 10, 150, 80, 200, 20);
with (movingField_txt){
autoSize = true;
html = true;
multiline = true;
type = “input”;
rordWrap = true;
}