Link to home
Start Free TrialLog in
Avatar of andreafp
andreafp

asked on

making a button go through a set of arrays

a button on the screen and an input text box also on the screen .The user has to put a b or c in the input box that corrisponds to an 0 or 1
as the button is pushed it checks if caracter entered is a b or c -- the string (values) is converted to an array
if the value entered is not a b or c it will go to frame 31 that worn to use proper caracters
if a b or c entered is = to one it will goand stop to frame 11 telling correct
else it will go to frame 21 where it will say incorrect because the letter chosen is value 0!






this code is on the first frame of time liner
values="a=0,b=0,c=1";



this code is on a button!
on(release) {
      if(((input.CharCodeAt(0)>64 && input.CharCodeAt(0)<68) || (input.CharCodeAt(0)>96
      && input.CharCodeAt(0)<100))) {
      valuesArray=split.values(",");
            for(var i=0;valuesArray.length;1++); {
                        if (input==valuesArray[i]);{
                              gotoAndStop(11);
                              }
                        else {gotoAndStop(21);
                        }
                  }

else {
      gotoAndStop(31);
}
}
ASKER CERTIFIED SOLUTION
Avatar of Savong
Savong
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of badrulnm
badrulnm

>> if (input==valuesArray[i])

It doesnt make sense. You are comparing string "a","b" or "c" with "a=0", "b=0" and "c=0"
I agree with Savong, what exactly is the problem?

also, input - is that your var value or instance name?
I'm thinking u're using instance name as you're using CharAt etc, in which case you'll need input.text to get what the user has typed in.

blu.
try this code for the button:

on (release) {
      var frame_num:Number;
      if (((input.CharCodeAt(0)>64 && input.CharCodeAt(0)<68) || (input.CharCodeAt(0)>96 && input.CharCodeAt(0)<100))) {
            valuesArray = values.split(",");
            for (var i = 0; i<valuesArray.length; i++) {
                  if (input == valuesArray[i]) {
                        frame_num = 11;
                        // break for loop if correct
                        break;
                  } else {
                        frame_num = 21;
                  }
            }
      } else {
            frame_num = 31;
      }
      gotoAndStop(frame_num);
}