I have a movie clip where actionscript takes place to check a user input.
The crux of what I'm trying to achieve is to check user input against 3 codes....
dave, koit & penguins.
If the user enters any code, then the playhead of the mc should go to flag "open" - and yet, it doesn't. It moves to the next frame which is in this instance "locked".
It should move to "locked" if the if statement returns a code other than those 3 above.
This is basic stuff and yet it doesn't want to play ball.
Can someone please look at the attached code and see if they can find it as I've been wracking my brain all day and yesterday.
Tried that, still won't work - removed all instances of this. but all that happens is that no matter what I press, locked gets played and then we go to open. The playhead just doesn't want to move where it is supposed to.
Dude, I founds a couple problems. The textfield names are changing, but if statements are referencing old variables. Some variables are not being populated BEFORE being placed in conditional.
Don't let the timeline control the variables...have the code to it.... I had started to make corrections....first have a single actionscript keyframe, and not multiple. Reuse many of the objects already on the stage. Using a switch statement instead of an if statement. Using the method you have now (timeline control) the user is forced to wait until the frame head reaches the appropriate frame and provides the correct response....
Step back a little and map out what you need and reorganize your project.
Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.
On frame 2 of this movie clip you can see that I have a key listener.
When the enter/return keys are pressed, whatever is in the input text box (Code, with variable name Codey) is validated. Or should be. If the input is say "dave", then a variable should be set and then the playhead should move to the frame label "open".
I've tried this.gotoAndPlay("open") and gotoAndPlay("open")
All the anim will do is take you to frame "locked" which should only happen if anything other than say "dave" is entered.
Why will the playhead not go to ("open") !?!?!
Stepping back and reassessing have not helped me find this little bug !!
I don't even know where to start.
1. frame 2: your "if" statements will run as soon as you enter this frame. They won't run again unless we leave the frame and then come back. so they are really doing nothing.
I entered dave and it said "open" I entered koit and it said "open" penguin did not work. You need to use trace() statements so that you can see what is going on behind the scenes.
It appears there is a lot going on. I would try to just focus on one part and getting that working, then move on to the next. I would dig a little more, but I am at work and can not have this on my screen.
You want to use if/else if statements. You just had if. Basically, when the code is run, first it checks to see if it is dave. If the answer is indeed dave, it still checks the other 2 if statements. the second if statement is false, it does not equal koit, and the third statement is false, it does not equal penguins, but the last if has an else statement, which says: if codey does not equal penguins, then go to and play"locked" which it does, and then goes to "open". by using if else if, once a statement is true, the statement is stopped.
frame 2:
your listener sends your playhead to the "open" frame, which will play to the code under the "openmenu" label. once you are at this code, your "if" statements will run, most tell the play head to go to and play "openmenu" which we are already at. so the play head then will proceed to frame 55 which then tells the play head to go to and play label "openmenu" so you are then stuck in a loop of the playhead going from label "openmenu" and frame 55. At this point if you enter any text, the last else statement will run sending you to the "openerror" label which sends us back the the "openmenu" label. If you now enter "dave" the playhead will go to label "alreadytwelve" which then proceeds to frame 55 which sends us back to openmenu. Have you ever used functions before?
You have a good start, it's just hard to figure out what exactly is going on when you start to add frames and labels. Like Samac said, step back, and maybe draw this out on paper what it is you want to do, then start building. Also build in small chanks and test frequently. If you try to code too much too fast it can get very hard to troubleshoot.
Tried that, and unfortunately, no joy. Now as soon as I press enter, nothing happens at all. See my updated flash version..........
This is really odd.
My plan is this, this little piece of a much larger animation is just a way of getting a user to enter "bonus codes" to unlock extra scenes. What it should do :-
Upon entry into the first frame, it should check to see which codes have already been entered (note there is a back button so people can come and go as they please - but I don't want them to have to enter the same codes again) and display the appropriate buttons and message.
If they do not have the main bonus code (in this case, "dave") then it should always ask for the 12 digit code......(that sounds weird I know but the actual bonus code will be 12 digits long when I've finalised everything.......
If a code has already been entered, I want the message to display "already entered"
If a code is invalid, I want the message to display "invalid"
On paper this is so simple, in my mind it's easy, yet I cannot translate it effectively to code.
Your help has been invaluable but if you can assist a little further I'd be ever so grateful.
1) The code works and does not allow errors that would lead to the code breaking. However, I also want an inbuilt checker that checks if a code has already been entered and then displays the appropriate message. As it stands, the incorrect code just gets deleted and we start again...... can that be done relatively easily ?
Is that something that can be rectified ?
Last edited by koit; 05-20-2009 at 01:54 PM.
Reason: Asking more info...
basically, we set 3 variables, then if they type one of the words, we set the variable to true, if they type it again, we will first check the variable, if it is true we will tell them already entered, if false, we continue and then set variable to true. Make sense?