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!