Jason,
Thanks for this. As you say, if I continue using the .text attribute it will still work but
will remove the html formatting which isn't what I want.
I tried using your routine which removes the last character or tag from a html text and it doesn't quite do what I need. The main problem is that the "maxscroll" property for htmlText seems to behave in a different way to normal text and almost always seems to be greater than 1 regardless of how many times you call getTextMinusOneCharacter - this results in the input field removing text which should
be kept.

Anymore thoughts on this would be welcome.

Joe

Date: Thu, 19 Oct 2006 08:41:14 -0600
From: "Jason Lutes" <[EMAIL PROTECTED]>
Subject: RE: [Flashcoders] htmlText and maxscroll
To: "Flashcoders mailing list" <flashcoders@chattyfig.figleaf.com>
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain;       charset="us-ascii"

Try using your original handler function even though the text field is
now HTML-enabled, because removing the last 'htmlText' character simply
pops off a (non-visible) closing tag's (likely </textformat>) final
angle bracket.

If this method destroys HTML formatting on your text, you can always use
the following code.

function getTextMinusOneCharacter(targetText:String,
presumeHTML:Boolean):String
{
  var lastBracketIndex:Number = targetText.lastIndexOf('<');
  while (lastBracketIndex > 0 && targetText.charAt(lastBracketIndex - 1)
== '>')
  {
    lastBracketIndex = targetText.lastIndexOf('<', lastBracketIndex -
1);
  }
  lastBracketIndex--;
  if (lastBracketIndex > 0 && presumeHTML !== false)
  {
    targetText = targetText.slice(0, lastBracketIndex) +
targetText.slice(lastBracketIndex + 1);
  }
  else
  {
    targetText = targetText.slice(0, targetText.length - 1);
  }
  return targetText;
}

this.textBox.onChanged = function():Void
{
  if (this.maxscroll > 1)
  {
    this.htmlText =
this._parent.getTextMinusOneCharacter(this.htmlText);
  }
};

Original post
>>
I'm trying to restrict text input into a field so that you can only
enter as much as will fit into the field and the rest gets cut off.

I was using code like

textBox.onChanged = function() {
         while (this.maxscroll>1) {
                 this.text = this.text.substr(0,-1);
         }
}

This works fine as long as its just plain text. However I need to use
html text so that the user can apply formatting.

If I try using

textBox.onChanged = function() {
         while (this.maxscroll>1) {
                 this.htmlText = this.htmlText.substr(0,-1);
         }
}

then Flash goes into an infinite loop. I did some debugging and it
looks like the value of maxscroll isn't the same for htmlText and so
removing the last character doesn't reduce maxscroll in the same way,
>>


Joe Cutting
Computer exhibits and installations
www.joecutting.com
96 Heslington Road, York, YO10 5BL
01904 627428
_______________________________________________
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