PDA

View Full Version : Decreasing Text Counter


irvinesteven
08-28-2004, 02:56 PM
Hey Everyone,

I need to create a text input box that has a counter above it that counts down from 160 to 0 (each character typed decreases the value by 1), on reaching zero the counter resets itself again and continues to decrese but displays a (2) next to it, informing the user that they are now on their second set of characters. E.g it would start as 160(1) then display 160(2), then 160(3) etc... much like the text message function on a Nokia Phone.

Any help with this would be much appreciated. And I thank in advance anyone that can work this out for me.

Thanks again..

SDI

wu-tang
08-28-2004, 08:48 PM
Here is a file with the an example of how to structure it. You will need to change the math a bit to go beyond 160 (2).

http://www.justintense.com/transfer/test.fla

irvinesteven
08-29-2004, 11:57 AM
Hey Wu-Tang you are a genius thanks man..

I owe you one. Just a quick question though being a bit of a novice to actionscript, what would be the best way to decrease the text fropm 160 to 0 instead of 0 to 160 like you have coded.

thanks again

irvinesteven

wu-tang
08-29-2004, 07:57 PM
no sweat my man. too decrease just change the math a bit... I think this bit of code should exactly what you want.


var count = 1;
var total = 160;

myField.addListener();

myField.onChanged = function(){

if(this.length >= this.curr)
{
var chars = (total * count) - this.length;
//trace("increase");
}
else if(this.length <= this.curr)
{
var chars = (this.length - (total * count)) * -1;
//trace("decrease");
}

amount.text = chars + " (" + count +")";

if(chars == 0) count ++;
if(chars == 160) count --;

this.curr = this.length;

}

irvinesteven
08-29-2004, 08:07 PM
Cheers dude, need to pull my finger out and get learning I think.

thanks again

SDI

wu-tang
08-29-2004, 08:12 PM
I just updated the code a bit so make sure you grab a copy again.

irvinesteven
08-29-2004, 08:37 PM
your a legend... Thanks

SDI

irvinesteven
08-29-2004, 08:40 PM
Wu Tang,

can you recommend a good resource guide to learning advanced actionscript. Have been using flash for a few years but concentrated on design side rather than serious coding.

cheers in advance

SDI