Copy link to clipboard
Copied
Hello and sorry for my English if a make mistake , i would like to cut a text with a length parameter, and not a special characters.
For example, i have this text :
Aujourd'hui, je suis allé chercher un livre.
And i would like have this sentence (with a parameter of "13" (for 13 characters for example)), when i click on a button :
Aujourd'hui j
e suis allé c
hercher un li
vre.
Peharps an actionscript3 like this logic:
text1.text = (line1.length = 13) + /n + line2.length = 13) + /n...
There's not a special characters, just the length because the text is unknow...
Thanks for your help
I continue to looking for a solution
Oops. Didn't instantiate the String. Fixed:
var s:String = "Aujourd'hui, je suis allé chercher un livre.";
var c:int = s.length;
var split:int = 13;
var n:String = "";
for(var i:int=0; i<c; i+=split){
n += s.substr(i, split+1) + "\n";
}
trace(n);
myText.text = n;
Copy link to clipboard
Copied
There's no property to do that, you can use line break in the string:
var _text:String = "Aujourd'hui, j" + "\n" + "e suis allé c" + "\n" + "hercher un li" + "\n" + "vre.";
Or:
textFieldName.text = "Aujourd'hui, j" + "\n" + "e suis allé c" + "\n" + "hercher un li" + "\n" + "vre.";
Copy link to clipboard
Copied
This should do it for you!
var s:String = "Aujourd'hui, je suis allé chercher un livre.";
var c:int = s.length;
var split:int = 13;
var n:String;
for(var i:int=0; i<c; i+=split){
n += s.substr(i, split+1) + "\n";
}
trace(n);
Copy link to clipboard
Copied
Oops. Didn't instantiate the String. Fixed:
var s:String = "Aujourd'hui, je suis allé chercher un livre.";
var c:int = s.length;
var split:int = 13;
var n:String = "";
for(var i:int=0; i<c; i+=split){
n += s.substr(i, split+1) + "\n";
}
trace(n);
myText.text = n;
Copy link to clipboard
Copied
Cool, these answers are fast !!
Thank you for your help, it works like i want
But i have changed a part of your script, this :
n += s.substr(i, split+1) + "\n";
because it repeat the last letter, at the beginning of the next line, for example :
Demain il fau
udra aller re
endre le livr
re.
And when i put this :
n += s.substr(i, split) + "\n";
It's ok
Demain il fau
dra aller ren
dre le livre.
Bye
Copy link to clipboard
Copied
and here's a more general solution:
function splitF(tf:TextField,s:String,n:int):void{
var a:Array = s.split('');
tf.multiline = true;
tf.text = a[0];
for(var i:int=1;i<a.length;i++){
tf.appendText(a);
if(i%n==0){
tf.appendText('\n');
}
}
}