flipTo TextField prototype

Clasificado bajo: AS2 (deprecated), Prototipos, String — drus @ 12:30 am

Prototipo extraido de layer51 y modificado para admitir etiquetas HTML.
Imita el estupendo efecto de texto de group94 de construcción de texto letra a letra, con variaciones aleatorias.

Actionscript:
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;
    for (var i = 0; i<T.oldtxt.length; i++) {
        if (T.oldtxt.charAt(i) != T.txt.charAt(i)) {
            T.backto = i;
            break;
        }
    }
    T.dir = -1;
    T.count = 0;
    T.onEnterFrame = function() {
        if (this.L == undefined) {
            this.L = this.targ.text.length;
        }
        if (++this.count>this.rot) {
            this.L = this.L+T.dir;
            this.count = 0;
        }
        var rndchar = chr(48+Math.random()*74);
        if (this.dir<1) {
            if (this.L>T.backto) {
                this.targ.htmlText = this.targ.text.substr(0, this.L-1)+rndchar;
            } else {
                this.dir = 1;
            }
        } else {
            if (this.L<=this.txt.length) {
                if (this.txt.charAt(this.L-1) == "<") {
                    var LT = this.L;
                    for (var i = 0; i<this.txt.length; i++) {
                        if (this.txt.charAt(i) == ">") {
                            this.L = i+1;
                            var tmp = this.txt.substr(0, this.L);
                            this.targ.htmlText = tmp;
                            break;
                        }
                    }
                    this.targ.htmlText = this.txt.substr(0, this.L-1);
                } else {
                    this.targ.htmlText = this.txt.substr(0, this.L-1)+rndchar;
                }
            } else {
                this.targ.htmlText = this.txt;
                this.onEnterFrame = undefined;
                this.removeMovieClip();
            }
        }
    };
};




AS_toolKit | Powered by WordPress | Skinned by Drus Unlimited | RSS Feed | Copyleft