How do I make a scroll bar for a text box?

  • Grissom7
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jun 09, 2006
  • Posts: 6
  • Status: Offline

Post June 9th, 2006, 4:36 am

Hi, I am wanting to have a text box that has a scroll bar on it, but I'm not sure how to do it. Any help would be great.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post June 9th, 2006, 4:36 am

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1254
  • Loc: Ro
  • Status: Offline

Post June 9th, 2006, 6:30 am

scroll text
“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. ”
  • Grissom7
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Jun 09, 2006
  • Posts: 6
  • Status: Offline

Post June 13th, 2006, 3:51 am

I tried doing what the site told me, but I can't get it to work the way I would like. I would like to have a large amount of text, but have only about 5 lines showing at a time, with the scroll buttons at the side.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1254
  • Loc: Ro
  • Status: Offline

Post June 13th, 2006, 6:50 am

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:
Code: [ Select ]
  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;
}
  1.   var strMyHugeText = "the huge text either from a file or hardcoded";
  2.   var RowPosition = 0;
  3.   var strLines5 = ParseLines(rowPosition, strMyHugeText);
  4. on scroll down:
  5.   rowPosition += 5;
  6.   strLines5 = ParseLines(rowPosition, strMyHugeText);
  7.   dynamicTextHolder.text = strLines5;
  8. on scroll up:
  9.   rowPosition -= 5;
  10.   strLines5 = ParseLines(rowPosition, strMyHugeText);
  11.   dynamicTextHolder.text = strLines5;
  12. function ParseLines(rowPosition, strHugeText)
  13. {
  14.   var crtLine = 0;
  15.   var iStrLen = strHugeText.length;
  16.   var strLines = "";
  17.  
  18.   for (i = 0; i< iStrLen; i++)
  19.   {
  20.     if (strHugeText[i] == 13) // that would be a line break
  21.      crtLine ++;
  22.     if (crtLine >= rowPosition && crtLine < rowPosition + 5)
  23.     {
  24.       strLines += strHugeText[i];
  25.     }
  26.    
  27.     if (crtLine >= rowPosition +5) // no need to read other lines
  28.      break; 
  29.   }
  30.   return strLines;
  31. }


way of solving no. 2 (using split) :
Code: [ Select ]
  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;
}
  1.   var strMyHugeText = "the huge text either from a file or hardcoded";
  2.   var RowPosition = 0;
  3.   var arrStringLines:Array = strMyHugeText.split("\n"); // get all the lines in an array
  4.    // maybe here can be: strMyHugeText.split("\r\n");
  5.   var strLines5 = ParseLines(rowPosition, strMyHugeText);
  6. on scroll down:
  7.   rowPosition += 5;
  8.   strLines5 = ParseLines(rowPosition, arrStringLines);
  9.   dynamicTextHolder.text = strLines5;
  10. on scroll up:
  11.   rowPosition -= 5;
  12.   strLines5 = ParseLines(rowPosition, arrStringLines);
  13.   dynamicTextHolder.text = strLines5;
  14. function ParseLines(rowPosition, arrStringLines)
  15. {
  16.   var crtLine = 0;
  17.   var iStrLen = strHugeText.length;
  18.   var strLines = "";
  19.   for ( iRowIndex = rowPosition; iRowIndex < rowPosition + 5; iRowIndex ++)
  20.   {
  21.     strLines += arrStringLines[iRowIndex] + "\n";
  22.   }
  23.  
  24.   return strLines;
  25. }


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. ”

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 36 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.