Damnit! This one is killing me, Help w/ Listener OBJ

i have this listener object below.
i also have a text area component called, “taPhoneNmbr”, that you type a phone number into.

what currently happens that the listener object will listen for change in the taPhoneNmbr.length.
once taPhoneNmbr.length reaches the value of the areacode it will add a hyphen to the end of the last character in taPhoneNmbr component.
same thing will happen once taPhoneNmbr.length reaches the value of prefix, resulting in a phone format like this: 800-555-1234

my problem now is that if i were to make a mistake with the number i’ve typed i cannot delete the last hyphen only because flash is constantly adding the hyphen through the listener.
so i added the removeEventListener at the end of the else if statement.
though i’m able to delete the hyphens, how do i “pause” the listener in the event where i either make changes to the prefix(not var) or area code(not var) portion of the taPhoneNmbr text?
i know i could mickey mouse it and cheat by creating a clear all button, but i figured i’d challenge myself.

var areacode:Number = 3;
var prefix:Number = 7;

var pnLstnr:Object = new Object ();
pnLstnr.change = function (evt_obj:Object) {
	if (taPhoneNmbr.length == areacode) {
		taPhoneNmbr.text += "-";
		Selection.setSelection (taPhoneNmbr.length,taPhoneNmbr.length);
	} else if (taPhoneNmbr.length == prefix) {
		taPhoneNmbr.text += "-";
		Selection.setSelection (taPhoneNmbr.length,taPhoneNmbr.length);
		taPhoneNmbr.removeEventListener ("change",pnLstnr);
	}
};
taPhoneNmbr.addEventListener ("change",pnLstnr);

any help on how to achieve these results will greatly be appreciated.
thank you in advance!

if I’m understanding the problem correctly:

one way that might work is to store the last character entered into a var, maybe save the charCode… so, you could then add some logic to see if the last char was a hyphen, is so, don’t place a new hyphen.

Other ideas may be - tracking the keys pressed - get the key codes. Then the delete or backspace keys should register specific keycodes - in your onchange, you could see if the last key pressed was a delete key. Similar to that, you could track total length of the string entered, and then if someone deletes a character, you’d see that the length became shorter… then some logic to do what you need to do.

You can set it up to remove/re-add the listener, but you’d have to have a separate key listener set up to detect input, then turn the listener back on… seems less clumpy to just run logic during the input in the other two ideas.

Hope this helps.

thanks, i’ll give that method a shot