let me think ... huge amount, only 5 lines/ scroll .... sounds impossible.
hahahahahaa, if there would be such thing as impossible.
well, directly no, u cant do that. But if you use you brain then it is very possible and very simple.
here it is; there can be added a lil bit more of optimising, but for the sake of a shorter code, i`ll let it like this:
way of solving no. 1:
var strMyHugeText = "the huge text either from a file or hardcoded";
var RowPosition = 0;
var strLines5 = ParseLines(rowPosition, strMyHugeText);
on scroll down:
rowPosition += 5;
strLines5 = ParseLines(rowPosition, strMyHugeText);
dynamicTextHolder.text = strLines5;
on scroll up:
rowPosition -= 5;
strLines5 = ParseLines(rowPosition, strMyHugeText);
dynamicTextHolder.text = strLines5;
function ParseLines(rowPosition, strHugeText)
{
var crtLine = 0;
var iStrLen = strHugeText.length;
var strLines = "";
for (i = 0; i< iStrLen; i++)
{
if (strHugeText[i] == 13) // that would be a line break
crtLine ++;
if (crtLine >= rowPosition && crtLine < rowPosition + 5)
{
strLines += strHugeText[i];
}
if (crtLine >= rowPosition +5) // no need to read other lines
break;
}
return strLines;
}
- var strMyHugeText = "the huge text either from a file or hardcoded";
- var RowPosition = 0;
- var strLines5 = ParseLines(rowPosition, strMyHugeText);
- on scroll down:
- rowPosition += 5;
- strLines5 = ParseLines(rowPosition, strMyHugeText);
- dynamicTextHolder.text = strLines5;
- on scroll up:
- rowPosition -= 5;
- strLines5 = ParseLines(rowPosition, strMyHugeText);
- dynamicTextHolder.text = strLines5;
- function ParseLines(rowPosition, strHugeText)
- {
- var crtLine = 0;
- var iStrLen = strHugeText.length;
- var strLines = "";
-
- for (i = 0; i< iStrLen; i++)
- {
- if (strHugeText[i] == 13) // that would be a line break
- crtLine ++;
- if (crtLine >= rowPosition && crtLine < rowPosition + 5)
- {
- strLines += strHugeText[i];
- }
-
- if (crtLine >= rowPosition +5) // no need to read other lines
- break;
- }
- return strLines;
- }
way of solving no. 2 (using split) :
var strMyHugeText = "the huge text either from a file or hardcoded";
var RowPosition = 0;
var arrStringLines:Array = strMyHugeText.split("\n"); // get all the lines in an array
// maybe here can be: strMyHugeText.split("\r\n");
var strLines5 = ParseLines(rowPosition, strMyHugeText);
on scroll down:
rowPosition += 5;
strLines5 = ParseLines(rowPosition, arrStringLines);
dynamicTextHolder.text = strLines5;
on scroll up:
rowPosition -= 5;
strLines5 = ParseLines(rowPosition, arrStringLines);
dynamicTextHolder.text = strLines5;
function ParseLines(rowPosition, arrStringLines)
{
var crtLine = 0;
var iStrLen = strHugeText.length;
var strLines = "";
for ( iRowIndex = rowPosition; iRowIndex < rowPosition + 5; iRowIndex ++)
{
strLines += arrStringLines[iRowIndex] + "\n";
}
return strLines;
}
- var strMyHugeText = "the huge text either from a file or hardcoded";
- var RowPosition = 0;
- var arrStringLines:Array = strMyHugeText.split("\n"); // get all the lines in an array
- // maybe here can be: strMyHugeText.split("\r\n");
- var strLines5 = ParseLines(rowPosition, strMyHugeText);
- on scroll down:
- rowPosition += 5;
- strLines5 = ParseLines(rowPosition, arrStringLines);
- dynamicTextHolder.text = strLines5;
- on scroll up:
- rowPosition -= 5;
- strLines5 = ParseLines(rowPosition, arrStringLines);
- dynamicTextHolder.text = strLines5;
- function ParseLines(rowPosition, arrStringLines)
- {
- var crtLine = 0;
- var iStrLen = strHugeText.length;
- var strLines = "";
- for ( iRowIndex = rowPosition; iRowIndex < rowPosition + 5; iRowIndex ++)
- {
- strLines += arrStringLines[iRowIndex] + "\n";
- }
-
- return strLines;
- }
personally i would use the second example, cos it's much faster even if it uses a bit more memory. First example is just to show there are more ways to solve the same thing, but some are better than the others.
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”