Input textfield counter?

I am making an input form in flash with a couple of multi-line input textfields. Let’s say they each allow max. 500 char. I have seen textfield charactercounters in javascript. ( “you have xxx characters left”). It’s a nice way to let your users howmuch typing space they have left. But now I am trying to make the same in flashMX, but it’s more compicated than I thought.

It’s easy to substract 1 from a variable every time a key is pressed. But sometimes people use the backspace, so then you detect what key it is, and in case of backslash, add 1 to your var.

But what if somebody selects half a sentence with the mouse and erases the whole chunck with one backspace stroke. How can I detect howmuch characters are gone? Or can I disable the use of mouse in an input textfield?

help !



you would have to have a loop of some kind that goes through and sees how many characters there are…i dont know exactly how to do it though :slight_smile:


this should work:

yourTextField.onChanged = function() {
yourTextField.selectable = false;



That won’t work eki. If the text area is unselectable, people can not type into it. So if you make it unselectable, it defeats the whole purpose.

You will probably need to become more familiar with the toString commands and such. I don’t know exactly how to do this, if I have time later, I might try something out.


I’m posting a file where it works! it stops working the minute u try to click on the text field, if u don’t touch the mouse it works as usual.



But what if people want to highlight and select an area? Then they have to start all over.

But that was what Stanley wanted! Wasn’t it?
(I mean that he wanted a way of disabling selections in an imput
text field)



why don’t you just use the text lenght property to get the number of chars in it?
you can use as is, or substract from your allowed max chars to update a dynamic text field with the result to let the user know how many he’s got left.
of course, this should be included in an on change event handler to update every time the text is changed (as the handler suggests… :wink: )
if you still can’t get it to work, i can script that for you, just say…

reply to eki: he didn’t want to disable the selection of text, but rather to calculate the amout of text selected (in the case of its deletion) then adjust the amout of text left (allowed to be typed) to be displayed accordingly. Unless I am wrong here???


Ok, here’s the examples,
textfields is counter, other is count down as you wanted.
It’s all fully commented,
each swf is only around 500 bytes, as it’s only script…

Very nice eyezburg.

Eyezberg, thanks for the fla. Well structured and nicely commented. It is exactly what I was trying to make. I didn’t know a “lenght”-property for a textfield existed. Always nice to learn something new…