Groups | Blog | Home
all groups > flash actionscript > april 2006 >

flash actionscript : multicolumn text layout


John Doe
4/13/2006 8:56:43 PM
hi:

i have a Flash movie (MX2004) receiving a string containing several
lines (carriage return separated). i need to show the text in 2 columns

i'm guessing the problem has probably been solved before and i don't
need to re-invent the wheel

thanks in advance for any ideas/suggestions

John Doe
4/14/2006 12:00:00 AM
[quoted text, click to view]

yes, like in a newspaper


[quoted text, click to view]

kglad
4/14/2006 1:56:00 AM
how is the text to be divided into two columns? is the first part of the text
to be in one column and the 2nd part of the text to be in the 2nd column? do
one or more of these columns need to scroll to accomodate all the text?
kglad
4/14/2006 2:25:25 PM
if your textfields have instance names tf1 and tf2 (and are non-html), and your
file returning your text is test.txt and it's returning the variable yourvar,
you can use:



lv = new LoadVars();
lv.onLoad = function() {
for (var i = 0; i<this.yourvar.length; i++) {
tf1.text = this.yourvar.substring(0, i);
if (tf1.maxscroll>1) {
break;
}
}
breakPt = this.yourvar.lastIndexOf(" ", i);
tf1.text = this.yourvar.substring(0, breakPt);
tf2.text = this.yourvar.substring(breakPt+1);
};
lv.load("test.txt");
John Doe
4/23/2006 7:56:43 PM
i just needed to make a little modification to avoid the last word in
the last line of left column appearing in first line of right column
when there was a car return in it

the only problem i have found so far is a slow performance with long
strings (as you can expect with string operations)

thanks for your help!


function setDesc(descText) {
var overflow:Boolean = false;

for (var i=0; i<descText.length; i++) {
desc_left.text = descText.substring(0, i);
if (desc_left.maxscroll>1) {
overflow = true;
break;
}
}

if (!overflow) {
desc_left.text = descText;
} else {
if (desc_left.text.charCodeAt(desc_left.text.length-2) == 13) {
breakPt = desc_left.text.length-2;
} else {
breakPt = descText.lastIndexOf(" ", i);
}
desc_left.text = descText.substring(0, breakPt);
desc_right.text = descText.substring(breakPt+1);
}
}



[quoted text, click to view]
kglad
4/23/2006 8:37:15 PM
AddThis Social Bookmark Button