PDA

View Full Version : text modification using buttons help needed



DrunkenMajestic
October 29th, 2004, 09:04 AM
Hi all, long time since ive posted here. Any way, my problem is this. I have a dynamic text field with space for only one character. The text field id embedded with a space and the 26 uppercase letters A-Z. The text field is intiated being empty. I have two buttons, and up and a down. When i press on the up button, i want the value in the text to be incremented by 1, for example, if it is a space, it should increment to an "A", if it is a "P" it should be incremented to a "Q", and if it is a "Z" it should be incremented so it goes back to being a space. I have managed to do this with a bunch of 27 if else statements, but surely there must be a way of simply incrementing the value in the text field?? The problem is i have 11 of these text fields all being modified from the one set of buttons, so using if else statements would take up about 2500 lines of code for 4 buttons, not very efficient, any help would be great guys. Cheers!

scotty
October 29th, 2004, 05:21 PM
I suppose you can do it more ways, but this is one;)

caps = new Array();
caps = [" ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
var nr = 0;
up_btn.onRelease = function() {
nr<caps.length-1 ? nr++ : nr=0;
info.text = caps[nr];
};
down_btn.onRelease = function() {
nr>0 ? nr-- : nr=caps.length-1;
info.text = caps[nr];
};

scotty(-:

JUD
October 29th, 2004, 05:30 PM
Just use an array. I've attached an example.

Oops!! Somebody beat me to it

scotty
October 29th, 2004, 06:43 PM
Here's a fla for 11 textfields and two buttons:)

scotty(-:

DrunkenMajestic
October 30th, 2004, 01:29 AM
Jeez guys!! im always surprised at how quickly you guys can reply, and how smart you all are, thanks to both of you for replying, you have helped me so much. cheers guys!