Copy link to clipboard
Copied
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;
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;
function clickedP(e:MouseEvent){
gotoAndStop(2);
}
Frame 7
import flash.events.MouseEvent;
function clickedP1(e:MouseEvent){
gotoAndStop(2);
}
If anyone can help me within the next 24 hours or so, it would be much appreciated.
Copy link to clipboard
Copied
WHile you create a score2 variable, I don't see it being incremented anywhere, so youy should start by making use of it. I do see a scvore variable being used, but I don't see it defined anywhere... that will be a problem.
As far as going to the wrong frame goes, try using the trace function in frame 5 to see if it actually makes it there when you say it doesn't... then see if the line that will send you to frame 7 executes when you think it shouldn't.
Copy link to clipboard
Copied
Can you please indicate which lines I will need to change and to what because I'm just getting more and more confused by this. Thanks.
Copy link to clipboard
Copied
Sorry, but this is a school assignment. I do not do people's schoolwork for them. I just offer ideas how to proceed. But for the trace code I mentioned, you could use it as follows for the lines that send you to frame 7 to see if you actually do go to frame 5...
if(score >= 500){
trace("in frame 5, going to frame 7");
gotoAndPlay(7);
}
Copy link to clipboard
Copied
It is now tracing "in frame 5, going to frame 7" to the output window, but it is still going to frame 7 instead of to frame 5. There is also an error that is appearing:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at code::SpriteSheetStage/loop2()
I don't really know what this means and what I can do to rectify this problem.
Copy link to clipboard
Copied
If it is tracing that output then that tells you that you do actually get to frame 5, but when you get to frame 5 it is determining that score >= 500 so it moves on to frame 7. I don't see where you even define/declare the score variable with the code you show, so that could be part of the problem.
As far as the 1009 error goes, it might be due to not having the score variable defined, but it could be something else as well...
The 1009 error indicates that one of the objects being targeted by your code is out of scope. This could mean that the object....
- is declared but not instantiated
- doesn't have an instance name (or the instance name is mispelled)
- does not exist in the frame where that code is trying to talk to it
- is animated into place but is not assigned instance names in every keyframe for it
- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).
If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now