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);
}
};
-
Jason
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf
> Of Joe Cutting
> Sent: Thursday, October 19, 2006 7:29 AM
> To: [email protected]
> Subject: [Flashcoders] htmlText and maxscroll
>
> Hello,
>
> 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,
>
> Anyone any cunning solutions or thoughts? I'm using Flash 8.
>
> Cheers
>
> Joe
>
>
> Joe Cutting
> Computer exhibits and installations
> www.joecutting.com
> 96 Heslington Road, York, YO10 5BL
> 01904 627428
>
_______________________________________________
[email protected]
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