I use this code to create a short text of 90 characters and than add three dots.
text = _root.shorttext1;
short = new String(text);
subshort = short.substr(0, 90)+" …";
Problem is that i don’t want to cut off the text in the middle of a word. How can I make sure flash never leaves half a word, but instead makes the string shorter so that it ends on a space character.
So instead of “word word word word word word word wo…”
I want “word word word word word word word …”
Problem is my design has only room for 90 chars. If I would allow the first 12 words, they could contain more than 90 letters…
the setup:
Each small block of text is set next to a thumbnail. Then people can click the thumb and then get a larger image, accompanied by the whole text…
// this is the text
myText = "Problem is that i don't want to cut off the text in the middle of a word. How can I make sure flash never leaves half a word, but instead makes the string shorter so that it ends on a space character.";
// slice it back to 90 characters
newText = myText.substr(0,90);
// put thos characters in an array
Words = newText.split(" ",99);
//loop tru the array, not including the last word
for(i=0;i<Words.length-1;i++){
// put the word including a space into a new var
shortText += Words*+" ";
}
// add 3 dots at the end
shortText += "...";
//and there you have it
trace(shortText)
// this is the text
myText = "Problem is that i don't want to cut off the text in the middle of a word. How can I make sure flash never leaves half a word, but instead makes the string shorter so that it ends on a space character.";
// slice it back to 90 characters
newText = myText.substr(0,87);
// put thos characters in an array
Words = newText.split(" ",99);
//loop tru the array, not including the last word
for(i=0;i<Words.length-1;i++){
// put the word including a space into a new var
shortText += Words*+" ";
}
// add 3 dots at the end
shortText += "...";
//and there you have it
trace(shortText)
this one will always return 90 characters, the previeus one, would return 93… (the 3 dots ;))
_root.maxdepth = unit_i.getDepth();
//the string part ...
myText = eval("_root.shorttext"+i);
// slice it back to 90 characters
newText = myText.substr(0,87);
// put thos characters in an array
Words = newText.split(" ",99);
//loop tru the array, not including the last word
for(t=0;t<Words.length-1;t++){
// put the word including a space into a new var
subshort += Words[t]+" ";
}
// add 3 dots at the end
subshort += “…”;
//
Dammit. I’m not in the clear yet :hangover: There’s a conflict going on here. With the code above, every duplicated (thumbnail-) movieclip gets the same tekst.
All the original texts are on the root and are named like this: _root.shorttext1
_root.shorttext2
_root.shorttext3
(dynamically loaded from an external file)
makeList = function () {
for (i=2; i<=_root.projectcount; i++) {
duplicateMovieClip("serviceunit", "serviceunit"+i, i);
unit_i = eval("serviceunit"+i);
unit_i.id = eval("_root.id"+i);
unit_i._y = 20; // edit this
unit_i.subclip.title = eval("_root.title"+i);
_root.maxdepth = unit_i.getDepth();
// this is the text
myText = eval("_root.shorttext"+i);
// slice it back to 90 characters
newText = myText.substr(0, 87);
// put thos characters in an array
Words = newText.split(" ", 99);
// loop tru the array, not including the last word
for (i=0; i<Words.length-1; i++) {
// put the word including a space into a new var
subshort += Words*+" ";
}
// add 3 dots at the end
subshort += "...";
// and there you have it
unit_i.subclip.shorttext = subshort;
unit_i.subclip.thumbcontainer.loadMovie("portfolio/thumb_"+unit_i.id+".jpg");
}
};
makeList();
this is without errors
and to make it more clear, here’s an function to cut the text
It’ll take me some time to make txtfiles to replace database information and clean up the fla a little. It’s also part of another movie. You’ll almost need the whole site or you’ll see nothing…