FORUMS: list search recent posts

Button Sequencing (how to code so that buttons must be pushed in a specific order)

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jeff Sinclair
Button Sequencing (how to code so that buttons must be pushed in a specific order)
on Mar 4, 2013 at 2:44:40 am

I am fairly new to actionscript programming, I've made a few simple games for the students in my class (They are learning English). I am working on a grammar/syntax game right now. I've made some simple flash games for them, but I think this will really help them, and they can use it at home.

I am trying to figure out how to write code for button sequencing.

Basically, what I want to happen is. I have 4 buttons: btn1, btn2, btn3, btn4.

1. The student needs to click each button which has an english word on it to make a correct sentence.
2. If they push it in the correct order, it goes to the next frame (frame 2).
3. If they make a mistake at any point, it goes to the error frame (frame 30) (and the values reset). In that frame, there is a "try again" button to push to go back to the first frame. This, I have working, as in, pushing the button and going from frame 30 to the first frame again.
4. Once it goes back to the first frame, with the values reset, they try again until they get it correct, and go on to frame 2.

For example, let's say the sequence was simply btn1, btn2, btn3, btn4. These are the button name,and the instance name for each button.
Thanks in advance, for even taking the time to read this!

Return to posts index

Sam Mattern
Re: Button Sequencing (how to code so that buttons must be pushed in a specific order)
on Mar 4, 2013 at 2:38:36 pm

If I am understanding you, for each question you need to define a sequence of buttons. The correction sequence for question one could be 4-2-1-3, for question two 1-2-4-3 and so on. If that's the case, you could store the sequence for each question in an array like so:

questionSeq = [4,2,1,3];
curAnswer = 0;

btn1.addEventListener(MouseEvent.CLICK, checkAnswer);
btn2.addEventListener(MouseEvent.CLICK, checkAnswer);
btn3.addEventListener(MouseEvent.CLICK, checkAnswer);
btn4.addEventListener(MouseEvent.CLICK, checkAnswer);

function checkAnswer(e:MouseEvent):void{
//trying to get the last character in the name of button pushed so that
//you can use the same function for every button
//should yield '1' for btn1, '2' for btn2
var whatBtnString:String =;
var whatBtn:Number = Number(whatBtnString); //need it as a number
trace("Button "+whatBtn+" pushed");//make sure you get 1 for btn1, 2 for btn2

if( question[curAnswer] == whatBtn){
//if the button pushed is equal to the first answer
curAnswer++;//increase curAnswer by 1 so that it points to next value in array = false; //disable the button so the user doesn't push it again and screw things up
if( curAnswer == 3){//if all four questions are answered
//hooray, you answered correctly, go to next question (next frame)
//wrong answer code -- go to frame 30;


I haven't tested this code, but you should be able to use this code on each frame, setting the order of the buttons in the array. You might have to enable all of the buttons at the top of the code on each frame, depending on how the scope of things works out.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved