Copy link to clipboard
Copied
Hi guys, I have some problem when creating "Hacking game". Inspired by Fallout hacking, I want to limit user to click (choose password). But the problem is, my script doesn't move to frame 2, even the i reach the limit, it still stay on the frame. How to make the while works well ? So after choose 3 wrong answer, it will move to frame 2 properly ?
Thanks for your help.
====The script====
import flash.events.MouseEvent;
stop();
mc_0.visible=false;
mc_1.visible=false;
mc_2.visible=false;
mc_3.visible=false;
mc_4.visible=false;
mc_5.visible=false;
var i:int=0;
while(i<=3)
{
btn_codes.addEventListener(MouseEvent.CLICK,corr);
btn_pages.addEventListener(MouseEvent.CLICK,two);
btn_cages.addEventListener(MouseEvent.CLICK,three);
btn_trial.addEventListener(MouseEvent.CLICK,zero);
btn_trees.addEventListener(MouseEvent.CLICK,two);
btn_cares.addEventListener(MouseEvent.CLICK,three);
btn_clamp.addEventListener(MouseEvent.CLICK,one);
btn_trump.addEventListener(MouseEvent.CLICK,zero);
btn_rests.addEventListener(MouseEvent.CLICK,zero);
function zero(e:MouseEvent){
mc_0.visible=true;
mc_1.visible=false;
mc_2.visible=false;
mc_3.visible=false;
mc_4.visible=false;
mc_5.visible=false;
i++;
trace(i);
}
function one(e:MouseEvent){
mc_1.visible=true;
mc_0.visible=false;
mc_2.visible=false;
mc_3.visible=false;
mc_4.visible=false;
mc_5.visible=false;
i++;
trace(i);
}
function two(e:MouseEvent){
mc_2.visible=true;
mc_1.visible=false;
mc_0.visible=false;
mc_3.visible=false;
mc_4.visible=false;
mc_5.visible=false;
i++;
trace(i);
}
function three(e:MouseEvent){
mc_3.visible=true;
mc_1.visible=false;
mc_2.visible=false;
mc_0.visible=false;
mc_4.visible=false;
mc_5.visible=false;
i++;
trace(i);
}
function four(e:MouseEvent){
mc_4.visible=true;
mc_1.visible=false;
mc_2.visible=false;
mc_3.visible=false;
mc_0.visible=false;
mc_5.visible=false;
i++;
trace(i);
}
function corr(e:MouseEvent){
mc_5.visible=true;
gotoAndPlay(3);
}
}
gotoAndPlay(2);
=====
The screenshot
stop();
mc_0.visible=false;
mc_1.visible=false;
mc_2.visible=false;
mc_3.visible=false;
mc_4.visible=false;
mc_5.visible=false;
var attempts:int = 0;
btn_codes.addEventListener(MouseEvent.CLICK,corr);
btn_pages.addEventListener(MouseEvent.CLICK,two);
btn_cages.addEventListener(MouseEvent.CLICK,three);
btn_trial.addEventListener(MouseEvent.CLICK,zero);
btn_trees.addEventListener(MouseEvent.CLICK,two);
btn_cares.addEventListener(MouseEvent.CLICK,three);
btn_clamp.addEventListener(MouseEvent.CLICK,one);
btn_trump
...Copy link to clipboard
Copied
stop();
mc_0.visible=false;
mc_1.visible=false;
mc_2.visible=false;
mc_3.visible=false;
mc_4.visible=false;
mc_5.visible=false;
var attempts:int = 0;
btn_codes.addEventListener(MouseEvent.CLICK,corr);
btn_pages.addEventListener(MouseEvent.CLICK,two);
btn_cages.addEventListener(MouseEvent.CLICK,three);
btn_trial.addEventListener(MouseEvent.CLICK,zero);
btn_trees.addEventListener(MouseEvent.CLICK,two);
btn_cares.addEventListener(MouseEvent.CLICK,three);
btn_clamp.addEventListener(MouseEvent.CLICK,one);
btn_trump.addEventListener(MouseEvent.CLICK,zero);
btn_rests.addEventListener(MouseEvent.CLICK,zero);
function zero(e:MouseEvent){
mc_0.visible=true;
mc_1.visible=false;
mc_2.visible=false;
mc_3.visible=false;
mc_4.visible=false;
mc_5.visible=false;
attempts++;
checkForLimitF();
}
function one(e:MouseEvent){
mc_1.visible=true;
mc_0.visible=false;
mc_2.visible=false;
mc_3.visible=false;
mc_4.visible=false;
mc_5.visible=false;
attempts++;
checkForLimitF();
}
function two(e:MouseEvent){
mc_2.visible=true;
mc_1.visible=false;
mc_0.visible=false;
mc_3.visible=false;
mc_4.visible=false;
mc_5.visible=false;
attempts++;
checkForLimitF();
}
function three(e:MouseEvent){
mc_3.visible=true;
mc_1.visible=false;
mc_2.visible=false;
mc_0.visible=false;
mc_4.visible=false;
mc_5.visible=false;
attempts++;
checkForLimitF();
}
function four(e:MouseEvent){
mc_4.visible=true;
mc_1.visible=false;
mc_2.visible=false;
mc_3.visible=false;
mc_0.visible=false;
mc_5.visible=false;
attempts++;
checkForLimitF();
}
function corr(e:MouseEvent){
mc_5.visible=true;
gotoAndPlay(3);
}
function checkForLimitF();
if(attempts>2){
gotoAndPlay(2);
}
}
Copy link to clipboard
Copied
Wow thanks for your help kglad.
I Didn't think about that.
Copy link to clipboard
Copied
you're welcome
Copy link to clipboard
Copied
Sorry, I have 1 question again...
How to add information for the limit ?
For example,
I've tried to put
keterangan.text="3 attemps left"; on initialization and add script to the checkLimit()
function checkLimit(){
if(attemps>3){
if(attemps==1) {
keterangan.visible=false;
}
else if(attemps==2){
keterangan.text="tried 2 of 4";
}
else if(attemps==3){
keterangan.text="YOUR_LAST_CHANCE";
}
else if(attemps==4){
gotoAndPlay(2);
}
}
But still, the text not changing, only show the initalization text (3 attemps left)
What did I missed ?
Thanks
Copy link to clipboard
Copied
function checkForLimitF();
if(attempts>3){
gotoAndPlay(2);
} else {
switch (attemps){
case 1:
keterangan.text='2 left';
break;
case 2:
keterangan.text='1 left';
}
}
}
Copy link to clipboard
Copied
Thanks a lot.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now