codice:
function charPositions(tFormat, str, depth) {
_root.createTextField("temp", depth, 0, -300, 100, 400);
temp.autosize = true;
temp.embedFonts = true;
temp.setNewTextFormat(tFormat);
var arr = [];
temp.text = str;
var totalWidth = temp.textWidth;
for (var i = 0; i<str.length; i++) {
temp.text = str.substr(i);
arr[i] = totalWidth-temp.textWidth;
}
return arr;
}
function setUpText(str, forma, lineLength) {
var positions = charPositions(forma, str, 2000);
var currentLine;
var lineHeight = forma.getTextExtent(str).height;
var finalPositions = [];
for (var i = 0; i<positions.length; i++) {
if (positions[i]>(lineLength+subtracta)) {
subtracta = positions[i];
currentLine++;
}
var x = positions[i]-subtracta;
var y = lineHeight*currentLine;
finalPositions[i] = {char:str.charAt(i), x:x, y:y};
}
return finalPositions;
}
function drawNext() {
var noo = this.createEmptyMovieClip("lett"+this.count, this.count);
var nextObj = charPos[this.count];
noo._x = nextObj.x;
noo._y = nextObj.y;
noo.createTextField("tex", 1, 0, 0, 100, 100);
noo.tex.text = nextObj.char;
noo.tex.embedFonts = true;
noo.tex.selectable = false;
noo.tex.setTextFormat(mt);
noo._alpha = 30;
noo.onEnterFrame = function() {
this._alpha += 5;
if (this._alpha>=500) {
this.onEnterFrame = function() {
if (this._alpha>=0) {
this._alpha -= 5;
} else if (this._alpha<0) {
delete this.onEnterFrame;
// se questo era l'ultimo movieclip,
// e siamo arrivati alla fine dell'animazione
// stabiliamo che tra 2 secondi verrà richiamata
// la funzione "Init" sulla root, passando i tre
// parametri iniziali
if(this.last){
_root.interval = setInterval(_root, "init", 2000, _root.str, _root.mt, 520);
}
this.removeMovieClip();
}
};
}
};
this.count++;
if (this.count>charPos.length) {
// se questo è l'ultimo movieclip della serie
// settiamo la variabile "last" come vera
noo.last = true;
delete this.onEnterFrame;
}
}
function init(str, tForm, lineLength) {
// resettiamo la variabile "subtracta"
// per poter reiniziare il ciclo
delete subtracta;
// rimuoviamo il campo di testo
temp.removeTextField();
// resettiamo l'intervallo di 2 secondi
clearInterval(interval);
charPos = setUpText(str, tForm, lineLength);
this.count = 0;
this.onEnterFrame = drawNext;
}
mt = new TextFormat();
mt.font = "Arial";
mt.size = 26;
mt.color = 0xffffff;
mt.bold = true;
str = "cosa hai da guardare!? sono troppo bello! scherzi a parte spero che vi possa piacere questo effetto!";
init(str, mt, 520);
stop();