Making a score counter without messing up already present code
I'm using Action Script 3.0 in Flash Professional for a uni project, and I am having a few problems with the code.
NOTE: This project is due in 2 days time (Friday 2nd May), so any help is urgent.
Firstly, I am not sure how to make a score counter without making the code that I already have present in the frame not work properly. What I am trying to do is have a score counter that adds 1 point every time that the mouse cursor touches a gold coin, and to lead to a game win frame once 20 gold coins have been caught.
Secondly, some of the buttons which lead to other frames won't work properly. For example, the button that is supposed to lead from the level 2 instructions screen in frame 4 is currently leading to the game win screen in frame 7 rather than the level 2 gameplay screen in frame 5.
This is the code that I have in frames 4 to 7 (the frames that are mainly causing the problems) at this point. Sorry that it takes up so much space.
Frame 4
import flash.events.MouseEvent;
stop();
ply_btn3.addEventListener(MouseEvent.MOUSE_UP,pClicked3);
function pClicked3(e:MouseEvent){
gotoAndStop(5);
}
Frame 5
import flash.events.Event;
import flash.events.MouseEvent;
var score2 = 0;
- stage.addEventListener(Event.ENTER_FRAME,loop2);
function loop2(e:Event){
if(score >= 500){
gotoAndPlay(7);
}
score++;
score_text.text = score;
var e12:int = Math.random() * 550;
var e22:int = Math.random() * 550;
var e32:int = Math.random() * 550;
var e42:int = Math.random() * 550;
var gc12:int = Math.random() * 400;
var gc22:int = Math.random() * 400;
var gc32:int = Math.random() * 400;
var gc42:int = Math.random() * 400;
var gc52:int = Math.random() * 400;
Egg1.rotation += 10;
Egg2.rotation += 10;
Egg3.rotation += 10;
Egg4.rotation += 10;
GoldCoin1.rotation += 10;
GoldCoin2.rotation += 10;
GoldCoin3.rotation += 10;
GoldCoin4.rotation += 10;
GoldCoin5.rotation += 10;
if(Egg1.y >= 407.95){
Egg1.x = e12;
Egg1.y = -96.00;
}
if(Egg2.y >= 407.95){
Egg2.x = e22;
Egg2.y = -266.00;
}
if(Egg3.y >= 407.95){
Egg3.x = e32;
Egg3.y = -135.00;
}
if(Egg4.y >= 407.95){
Egg4.x = e42;
Egg4.y = -164.00;
}
if(GoldCoin1.y >= 407.95){
GoldCoin1.x = gc12;
GoldCoin1.y = -278.00;
}
if(GoldCoin2.y >= 407.95){
GoldCoin2.x = gc22;
GoldCoin2.y = -315.00;
}
if(GoldCoin3.y >= 407.95){
GoldCoin3.x = gc32;
GoldCoin3.y = -207.00;
}
if(GoldCoin4.y >= 407.95){
GoldCoin4.x = gc42;
GoldCoin4.y = -221.00;
}
if(GoldCoin5.y >= 407.95){
GoldCoin5.x = gc52;
GoldCoin5.y = -118.00;
}
Egg1.y += 10;
Egg2.y += 10;
Egg3.y += 10;
Egg4.y += 10;
GoldCoin1.y += 10;
GoldCoin2.y += 10;
GoldCoin3.y += 10;
GoldCoin4.y += 10;
GoldCoin5.y += 10;
}
Egg1.addEventListener(MouseEvent.MOUSE_OVER,moe12);
function moe12(e:MouseEvent){
gotoAndStop(6);
}
Egg2.addEventListener(MouseEvent.MOUSE_OVER,moe22);
function moe22(e:MouseEvent){
gotoAndStop(6);
}
Egg3.addEventListener(MouseEvent.MOUSE_OVER,moe32);
function moe32(e:MouseEvent){
gotoAndStop(6);
}
Egg4.addEventListener(MouseEvent.MOUSE_OVER,moe42);
function moe42(e:MouseEvent){
gotoAndStop(6);
}
GoldCoin1.addEventListener(MouseEvent.MOUSE_OVER,mogc12);
function mogc12(e:MouseEvent){
GoldCoin1.y = -278.00;
}
GoldCoin2.addEventListener(MouseEvent.MOUSE_OVER,mogc22);
function mogc22(e:MouseEvent){
GoldCoin2.y = -315.00;
}
GoldCoin3.addEventListener(MouseEvent.MOUSE_OVER,mogc32);
function mogc32(e:MouseEvent){
GoldCoin3.y = -207.00;
}
GoldCoin4.addEventListener(MouseEvent.MOUSE_OVER,mogc42);
function mogc42(e:MouseEvent){
GoldCoin4.y = -221.00;
}
GoldCoin5.addEventListener(MouseEvent.MOUSE_OVER,mogc52);
function mogc52(e:MouseEvent){
GoldCoin5.y = -118.00;
}
Frame 6
import flash.events.MouseEvent;
- pAgain.addEventListener(MouseEvent.MOUSE_UP,clickedP)
function clickedP(e:MouseEvent){
gotoAndStop(2);
}
Frame 7
import flash.events.MouseEvent;
- pAgain.addEventListener(MouseEvent.MOUSE_UP,clickedP1)
function clickedP1(e:MouseEvent){
gotoAndStop(2);
}
If anyone can help me within the next 24 hours or so, it would be much appreciated.
