PDA

View Full Version : Detect number of lines of text and then break?


Xstream
02-24-2006, 08:55 PM
Hi AS friends,

Anyone know how i can split up dynamicly loaded text according to the number of lines that are allowed? I'v managed to make it work after a week of searching and trial and error, but it's based on the amount of characters, what is not what i want because i've got no control over the actual height of the text since the concentration of characters differ per page.

This is what i mean: The Website (http://www.amparanoia.nl/mansan)

This is the code:

System.useCodepage = true;
textLength = 760;
n = 0;
index = n + 1;

homeText.html = true;
homeText.multiline = true;
homeText.wordWrap = true;
homeText.condenseWhite = true;

myData = new LoadVars();
myData.onLoad = function(success) {
if (success) {
tarray = new Array();
for (i=0; i<(this.homeText.length/textLength); i++) {
splitvar = this.homeText.substr((i*textLength), textLength);
tarray.push(splitvar);
}
homeText.htmlText = tarray[n];
} else {
homeText.htmlText = "error loading";
}
};

myData.load("mansanText.html");

btLeesMeer.onRelease = function():Void {
homeText.htmlText = tarray[index++];
}

Is it possible to set the number of lines that are allowed and then split the text? I already have been playing with text._height and text.textHeight etc but it's just beyond me. I'm not that advanced in Flash AS yet.

If anyone can help me out here i would be very gratefull!

Thanx in advance.

Xs.

flashead
02-24-2006, 11:40 PM
that's going to get tricky.
i looked all through the AS reference and couldn't find anything that might help.
what effect are you trying to achieve? because judging by your code it looks like you've got a large block of text, and it won't all fit in your text field, so you want to split it up into little portions that will fit. and on the press of a button you want to swap the first bit of text out for the second bit.

is that right?
if that's what you're trying to do, you have the option of putting all the text in the text field at the start. then use the bottomScroll property to get the number of visible lines in your text field and then onPress just adjust the scroll property of the text field by the amount returned by bottomScroll.

k.

Xstream
02-25-2006, 10:09 AM
OK, i get the idea... might do the trick :D

Yes, it's what i'm trying to achieve. Because it does not fit all in that block i need a way to make it "look" it goes to the next page, ur idea might work :D

Could you give me an idea on how to approach this?

flashead
02-26-2006, 06:20 PM
here's a simple example of what i mean:
var myString = "Lorem ipsum dolor sit amet..."; // your long string
txtField.text = myString;

var lines = txtField.bottomScroll;

downBtn.onRelease = function()
{
txtField.scroll += lines;
};

upBtn.onRelease = function()
{
txtField.scroll -= lines;
};

k.