Skip to content

Instantly share code, notes, and snippets.

@chromeragnarok
Created March 1, 2011 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chromeragnarok/848849 to your computer and use it in GitHub Desktop.
Save chromeragnarok/848849 to your computer and use it in GitHub Desktop.
a bit of the recursive function for paging. caution, this is not the full code.
function generatePaging(fetchSize:Number=128):void
{
var buffer:Array = new Array();
var i:Number = 0;
while (i < fetchSize && wordIndex + i < textArray.length)
{
var word:String = textArray[wordIndex + i];
buffer.push(word);
i++;
}
var bufferToBePushed:String = buffer.join(" ");
var wordsToBeWritten:String = pageArray[pageIndex] == null ? bufferToBePushed : pageArray[pageIndex] + " " + bufferToBePushed;
textContent.htmlText = wordsToBeWritten;
if (textContent.textHeight > textContent.height - 20)
{
fetchSize = fetchSize / 4;
if (buffer.length == 1)
{
pageArray[pageIndex] = wordsToBeWritten;
wordIndex = wordIndex + i;
pageIndex++;
return;
}
else
{
generatePaging(fetchSize);
}
}
else
{
pageArray[pageIndex] = wordsToBeWritten;
wordIndex = wordIndex + i;
generatePaging(fetchSize);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment