hi, every experts here. this following simple code has spent too much of my time, I debuged every single step, and each step works as expected, but why the result is no as expected, can u guys help me out. thanks a lot!
MovieClip.prototype.createJustifiedText = function(name, depth, x, y, width, text, format) {
this.createEmptyMovieClip(name, depth);
this[name].createTextField("tempCamp", 10000, 0, 300, 0, 0);
this[name].tempCamp.setNewTextFormat(format);
this[name].tempCamp.text = "lala";
this[name].tempCamp.autoSize = true;
this[name].tempCamp.embedFonts = true;
var iniY = this[name].tempCamp._height;
this[name].tempCamp.text += newline+"lala";
var finY = this[name].tempCamp._height-iniY;
this[name].tempCamp.removeTextField();
var posX = 0;
var posY = 0;
var j = 0;
var l = 0;
var promedio = 0;
this[name]._x = x;
this[name]._y = y;
var aSaltos = text.split(String.fromCharCode(13));
for (var ij = 0; ij<aSaltos.length; ij++) {
var aTexto = aSaltos[ij].split(" ");
for (var i = 0; i<aTexto.length; i++) {
l++;
this[name].createTextField("campo"+l, l, posX, posY, 0, 0);
this[name]["campo"+l].setNewTextFormat(format);
this[name]["campo"+l].text = aTexto*;
this[name]["campo"+l].autosize = true;
this[name]["campo"+l].embedfonts = true;
this[name]["campo"+l].selectable = false;
posx += this[name]["campo"+l]._width;
aLinea[j] = "campo"+l;
j++;
if (posX>width) {
posY += finY;
posx -= this[name]["campo"+l]._width;
this[name]["campo"+l].removeTextField();
i--;
promedio = (width-posX)/(j-2);
for (k=1; k<aLinea.length; k++) {
this[name][aLinea[k]]._x += promedio*k;
}
aLinea = new Array();
j = 0;
posX = 0;
}
}
j=0;
posX=0;
posY+=finY;
}
};
myformat = tf.getTextFormat();
mytext = tf.text;
_root.createEmptyMovieClip("mcT", 100);
mcT.createJustifiedText("test", 10000, 10, 10, 20, mytext, myformat); [FONT=Courier New][/FONT]
tf is a text filed on stage with some text in.
result should be a new text filed created on the stage besides the old one.