Had a wee play and after a request supplied this…
It is a basic way of breaking some block text into an array of lines of text
here is the class ====> call it createIndividualTextLines.as
/*
PURPOSE -- to cut a string into lines of text
// EXAMPLE USAGE
(desired char length:Number, textString, _parentRef, callback function);
n = new createIndividualTextLines (56, txt, this, someCallBackFunc);
function someCallBackFunc (a, _this) {
trace ("callback");
}
*/
class createIndividualTextLines {
//
private var len:Number;
private var origLen:Number;
private var txt:String;
private var a:Array;
private var line:String;
private var _this:MovieClip;
private var callback:Function;
//
function createIndividualTextLines (_len:Number, _txt:String, _parentRef:MovieClip, _callback:Function) {
len = _len;
txt = _txt;
a = new Array ();
_this = _parentRef;
callback = _callback;
init ();
}
function init () {
origLen = len;
for (var i = 0; i < txt.length; i++) {
len = origLen;
line = txt.slice (0, len);
if (line.charAt (line.length - 1) != " ") {
// ---------- test failed!
for (var j = 0; j < txt.length - 1; j++) {
// increment one more character until we hit a " "
len++;
line = txt.slice (0, len);
// test again
if (line.charAt (line.length - 1) == " ") {
// found next " " so break nested for loop and test next line
a.push (line);
break;
} else if (txt.length < len) {
// capture last entry
a.push (line);
break;
}
}
} else {
// we were lucky a " " was excactly were we wanted it to be
line = txt.slice (0, len);
a.push (line);
}
// remove tested line from testing string
txt = txt.slice (len, txt.length);
}
callback (a, _this);
}
}
and here is a usage…
on frame one…
txt = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
//
var txtLined = new createIndividualTextLines (56, txt, this, bfgh);
//
function bfgh (n, _this) {
numberOfLines = n.length;
for (var i = 0; i < numberOfLines; i++) {
trace( n* ) ;
}
}