Copy link to clipboard
Copied
the issue I am having is that every time I click my "next" button after frame 62 it skips a frame, is there a way I can fix this? here is my .fla https://docs.google.com/leaf?id=0B1F8xODVvfASYzcxZTE4NWItNjg0ZS00ZmE0LTk2NzctNzBkODc4NjliMTM1&hl=en
if its easier his is the two frames of code im using
Frame 61:
stop();
ans_btn.addEventListener(MouseEvent.MOUSE_UP, onClick);// Declare event
function onClick(event:MouseEvent):void {
var answer:String=ans_txt.text;// Turn imput into string
var ans:Number=Number(answer);// Turn that string into a number
switch (ans) {
case 3 :// Made correct answer first with additon to b int
show_txt.text="Correct";
b=b+1;
nextFrame();
break;
case 1 :// Other possible answers
case 2 :
case 4 :
show_txt.text="Try Again";
break;
default :
show_txt.text="1 to 4 only";
break;// Default answer shows when something not listed is showen
}
a=a+1;// Add 1 to the a int
}
Frame 62:
stop();
next_btn.addEventListener(MouseEvent.MOUSE_UP, goNext);
{
trace(a,b);
};
Hello again.
Here is another file that is not skipping frames. You will have to correct some things.

First of all, notice that when we add an eventlistener to a button called/instantiated as "goNext" in the firstFrame on the timeline, this eventlistener will continue working through all the timeline whenever a button named "goNext" show up.
This way you don't have to keep adding listeners to the same button again and again.
The same thing happens with your answer button... if you add a listener to i
...Copy link to clipboard
Copied
What is the rest of the code for your next button?
Copy link to clipboard
Copied
next_btn.addEventListener(MouseEvent.CLICK, goNext);// Move to next frame
function goNext(event:MouseEvent):void {
nextFrame();
if (currentFrame<=2) {
play();
}
}
on the first frame
Copy link to clipboard
Copied
Hello again.
Here is another file that is not skipping frames. You will have to correct some things.

First of all, notice that when we add an eventlistener to a button called/instantiated as "goNext" in the firstFrame on the timeline, this eventlistener will continue working through all the timeline whenever a button named "goNext" show up.
This way you don't have to keep adding listeners to the same button again and again.
The same thing happens with your answer button... if you add a listener to it that will run a function called, for example, "checkAnswers", the function "checkAnswers" will work for all buttons in any other frame on the timeline from that point on.
So, in your file on frame 61 we have this:
ans_btn.addEventListener(MouseEvent.MOUSE_UP, onClick);
function onClick (event:MouseEvent):void {
trace("Do this");
}
Now, if you add another button on frame 62 called "ans_btn", it will be created already listening for the function "onClick" and, if clicked will run that function on frame 61.
This is just a simple way that I've found to explain what is going wrong with your file. The next button, somehow, is going nextFrame two times probably because you keep adding listeners to it.
Notice too that in the attached file, all the answers will be correct if you type 3, because of the first function.
An easy way to solve this is create an answer button 2 with a onClick2 function... an answer button 3 with an onClick3 function and so on... this is not the best way to do it, but will solve your problem for now...
And, one more thing... all your functions could be written in the first frame... you just have to pay attention when adding listeners to buttons because if you try to add a listener on frame 22 to a button that don't exist on frame 22, it will throw an error.
Hope it help you.
Copy link to clipboard
Copied
once again you save the day, thanks again newToAS3
Copy link to clipboard
Copied
You're welcome! 😃
Copy link to clipboard
Copied
hey sorry to bring this back up, but for some reason the code broke this morning, it was working last night but its being a bully today. do you think you could take a look at it? it seems to be doing the same thing I mentioned before but without the intended results.
Copy link to clipboard
Copied
me8myself4 wrote:
do you think you could take a look at it?
Sure!
I think I already solved the problem... at least now I'm not seeing any strange behavior in your file. To solve it, just cut the following functions from frame 61 to frame 1 and see if this is working the way you want... if not, tell me what's not working ok?
move functions onClick, onClick2, onClick3, onClick4, onClick5 and onClick6 from frame 61 and paste them into frame 01 right after goNext function.
And don't move the button listeners... leave them where they are now.
Hope it works 😃
Copy link to clipboard
Copied
I moved all but the ans_btn event listener over and I am still recieving the same grief, any other idea's? or maby I somehow did that part wrong?
Copy link to clipboard
Copied
Check this file here

and check if this is working the way you expect...
When you finish this file, I would sugest you to start with it all over leaving out what is unecessary. There are things that you could improve in your code.
I guess you have some background in programming don't you? How are you learning AS3? There are things you're using that is not easy for me to understand so, when you finish your file, it will be nice to ask someone else to help you improve it, for as you can see by my nick here, I'm still new to AS3. =P
Anyway, I hope this file works for you and get back here if you have more doubts... It's a pleasure to help while I can.
Copy link to clipboard
Copied
looks like im getting the same problems, altho it now restarts at the proper frame, so I guess we are moving toward the goal. I have tried removing the event listeners but that dosen't seem to do anything, any other ideas?
also this is the first programming i have done. it's a final for a class I have been taking online.
Copy link to clipboard
Copied
Could you try to explain me what is not working properly?
As I pass through the file, everything seems to be working... maybe there's something I'm missing.
Tell me the frame where something should be working but it's not.
Copy link to clipboard
Copied
After you click "back" on frame 133 and start to do the test over again it goes to 60 (correct) then to 62 (incorrect) 64 (incorrect) ext ext and when it is to play the small example it just stops at the first frame, what do you see when you do this?
Copy link to clipboard
Copied
Uh, I see... the same thing happens here.
I notice you added eventListeners for buttons ans1, ans2, ans3... but all the answer buttons on stage are named ans_btn... you should change that.
I did it but the problem is still there.
It seems that when you get back to frame 61 for example, the correct answer is still there so you should reset that at the end of your switch to the right function. I tried doing so but it didn't work... another thing that could be happening is that somehow the "goNext" function is running twice and jumping a frame, but I don't get it. =/
I'll try a little bit more later but I don't know if I'll be able to solve the problem =(
Copy link to clipboard
Copied
I have tryed adding removeEventListener(Event.ENTER_FRAME (onClick, onClick2, onClick3, onClick4, onClick5, onClick6, goNext)); but this seems to have no effect on it
do you know of a way to make it switch case after i have chosen it before it moves to a new frame
I removed the break stament from the case to make it move to the next one, this worked for the first question but am getting same problem with following ones
Edit: Never mind I have found my error, at the second last page there was a event listener hiding there causing me problems
Message was edited by: me8myself4
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more