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?
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.
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… )
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…
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…
greetz
Stanley
Creating engaging and entertaining content for designers and developers since 1998.