Joe,

Try adding #getLineCount to the mix. It should help ensure your text
never exceeds the field boundaries.

Note that I re-instated your original while loop in my handler. I
discovered that is was in fact necessary the first time I copied and
pasted text into my test-it-out field. I also slightly re-factored
#getTextMinusOneCharacter.

// Returns one of two possible things, depending on the "countType"
argument:
// 1. Total lines occupied by text within a field (passing a "text"
argument, or nothing).
// 2. Display height of a field, measured in lines (passing a "field"
argument).
function getLineCount(targetField:TextField, countType:String):Number
{
  if (targetField instanceof TextField)
  {
    var lineCount:Number;
    var originalScrollPosition:Number;
    countType = countType.toLowerCase() != 'field' ? 'text' : 'field';
    originalScrollPosition = targetField.scroll;
    targetField.scroll = countType == 'text' ? targetField.maxscroll :
1;
    lineCount = targetField.bottomScroll;
    targetField.scroll = originalScrollPosition;
    return lineCount;
  }
}

// Retrieves the specified string without the last non-HTML character.
function getTextMinusOneCharacter(targetText:String,
presumeHTML:Boolean):String
{
  var lastBracketIndex:Number;
  if (presumeHTML !== false)
  {
    lastBracketIndex = targetText.lastIndexOf('<');
    while (lastBracketIndex > 0 && targetText.charAt(lastBracketIndex -
1) == '>')
    {
      lastBracketIndex = targetText.lastIndexOf('<', lastBracketIndex -
1);
    }
    lastBracketIndex--;
  }
  if (typeof lastBracketIndex == 'number' && lastBracketIndex > 0)
  {
    targetText = targetText.slice(0, lastBracketIndex) +
targetText.slice(lastBracketIndex + 1);
  }
  else
  {
    targetText = targetText.slice(0, targetText.length - 1);
  }
  return targetText;
}

this.textBox.onChanged = function():Void
{
  while (this._parent.getLineCount(this, 'text') >
this._parent.getLineCount(this, 'field'))
  {
    this.htmlText =
this._parent.getTextMinusOneCharacter(this.htmlText);
  }
};


-
Jason 

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to