Copy link to clipboard
Copied
I have a basic knowledge of Animate, and so far have relied on code snippets to achieve what I need. However I am developing a game where the user has to click on a choice of 14 buttons in the correct sequence to progress thought the level. The number of clicks needed in each sequences different. I am currently doing this by:-
stop();
Button_1.addEventListener(MouseEvent.CLICK, MoveOnBTN1);
function MoveOnBTN1(event:MouseEvent):void
{
gotoAndPlay(19);
}
stop();
Button_2.addEventListener(MouseEvent.CLICK, MoveOnBTN2);
function MoveOnBTN2(event:MouseEvent):void
{
gotoAndPlay(24);
}
The other buttons turn red if they are clicked on to show the incorrect sequence.
Is there a way of keeping track of the correct clicks and showing the user a percentage of correct clicks at the end of each level?
I also have a help button, this helps the user click the next button in the sequence, would there be a way of showing how many times the help button is used?
Sorry that this is so very specific!
Thank you in advance for any help.
there is, but it's going to be messy with the approach you've taken.
it would be simpler to implement, expand and debug to use something like:
var button_num:int = 0;
var correct_num:int;
var incorrect_num:int;
var correct_buttonA:Array = [12,11,3,1,etc..]; // Button_12 should be clicked first, then Button_11, then 3, then 1 etc
for(var i:int=;i<correct_buttonA.length;i++){
this["Button_"+i].addEventListener(MouseEvent.CLICK,buttonF);
}
function buttonF(e:MouseEvent):void{
if(e.currentTarget.name=="Butto
...Copy link to clipboard
Copied
there is, but it's going to be messy with the approach you've taken.
it would be simpler to implement, expand and debug to use something like:
var button_num:int = 0;
var correct_num:int;
var incorrect_num:int;
var correct_buttonA:Array = [12,11,3,1,etc..]; // Button_12 should be clicked first, then Button_11, then 3, then 1 etc
for(var i:int=;i<correct_buttonA.length;i++){
this["Button_"+i].addEventListener(MouseEvent.CLICK,buttonF);
}
function buttonF(e:MouseEvent):void{
if(e.currentTarget.name=="Button_"+correct_buttonA[button_num];
correct_num++;
button_num++;
// indicate correct button was clicked
if(button_num==correct_buttonA.length-1){
// game over. do whatever
}
} else {
incorrect_num++;
// turn e.currentTarget red
}
}
var help_num:int=0;
help_button.addEventListener(MouseEvent.CLICK,helpF);
function helpF(e:MouseEvent):void{
help_num++;
// the correct button is "Button_"+correct_buttonA[button_num];
}
Copy link to clipboard
Copied
Thank you for your reply, much appreciated!
Due to only having a basic knowledge of Animate and coding I don't understand how to use this code sorry, also I have already created a lot of levels to my game and would prefer to add something to the existing code rather then changing everything I've already done.
You mention a messy way of doing it with the approach I've taken, what would this be? and is it more complicated then what you have already sent?
Sorry for my lack of understanding, and thanks for your help.
Copy link to clipboard
Copied
create variables that track the info you want to track. you'll need to update those variables in the appropriate functions.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now