dcsimg
A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: I need advice

Hybrid View

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Posts
    113

    I need advice

    I thought I understood this but I guess I don't. I am working on a practice quiz and want to show a timer while students take the quiz. I have a getTimer on a movie clip on frame 5 and a getTimer on the try again button on frame 7. I am using an array to dynamically load jpegs and to load the questions and answers. Everything works fine except that when I use the try again button to reset the quiz my timer doesn't reset. The quiz has 20 questions. You can use the number keyboard (A = 1, B = 2, C = 3, D = 0)to quickly go to the end of the quiz. Can someone please take a look and give me suggestions. Flash is just a hobby for me so I am no expert. Of course the pics won't load from here.
    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Apr 2002
    Posts
    113
    I'm still looking for help. Can one of you really smart paople out there please take a look at my code in the above .fla? Here is a link to my work in progress so the jpegs load. Thanks.

    http://members.tripod.com/spanishfla.../quizFoods.swf

  3. #3
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Change your timer script to this:
    Code:
    onClipEvent (enterFrame) {
    	Time = Math.round((getTimer() - _root.last_test_time) /1000);
    	if (Time<10) {
    		_root.elapsedTime = "00"+Time+"  seconds have passed.";
    	} else if (Time>9 & Time<100) {
    		_root.elapsedTime = "0"+Time+"  seconds have passed.";
    	} else if (Time>=100) {
    		_root.elapsedTime = Time+"  seconds have passed.";
    	}
    }
    onClipEvent (unload) {
    	_root.finalTime = "You finished the quiz in  " + Time +  "  seconds."
    }
    Change your replay button script to this:
    Code:
    on (release) {
    	_root.last_test_time = getTimer();
    	message="";
    	gotoAndPlay(4);
    }
    One last note... You shouldn't have spaces (quiz jan 8 03.fla) in your files names, that'll get you in trouble!

  4. #4
    Senior Member
    Join Date
    Apr 2002
    Posts
    113
    on (release) {
    _root.last_test_time = getTimer();
    message="";
    gotoAndPlay(4);
    }
    Thanks. It worked great. Looking at your code... Does last_test_time have any significance? Wouldn't my variable name work also? I believe the primary difference is message="";.
    I assume that is just a holder for the variable value. If I don't have that line my variable isn't remembered? Thanks for saving the day. I enjoy following your threads because you always seem to have the right answer. I almost emailed you to ask you to take a look but I held back.

  5. #5
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    No, last_test_time has no particular significance. It could of been your variable name. But I think there was some confusion because your replay button's instance name was also "currentTime". In any case, I traced your "_root.currentTime.currentTime" in your timer movie clip script, and it was allways undefined, indicating that it was never changed by your button script.

    message=""; was just to clear that textfield on a replay, because otherwise you would still see "Game Over....", when playing a new game.

  6. #6
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Hi,

    I saw the problem was now solved by oldnewbie but I had a look at your fla and came up with a different idea than getTimer and instead use setInterval. Check the code in frames 1, 4 and in the try it again button. This is an alternative and very simple solution for a timer and easy to set back.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  7. #7
    Senior Member
    Join Date
    Apr 2002
    Posts
    113
    Thanks. You guys are great. I really appreciate the help. Both methods work great. I'm not sure I fully understand the function you wrote. Let me see...??? The setInterval adds 1 to the Time variable every 1000 milliseconds. On frame 7 it is cleared. Why does Time=1 at the start?

    Time=1;
    function recordTime(){
    myPause=new Object;
    myPause.interval=function(){
    if (Time<10) {
    elapsedTime = "00"+Time+" seconds have passed.";
    }
    if (Time>9 & Time<100) {
    elapsedTime = "0"+Time+" seconds have passed.";
    }
    if (Time>=100) {
    elapsedTime = Time+" seconds have passed.";
    }
    if(_currentframe==7){
    clearInterval(myTimer);
    }
    Time++;
    }
    myTimer=setInterval(myPause,"interval",1000);
    }


    Any further explanation on your part would be greatly appreciated.



  8. #8
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    I think the time should start at 0. So time=0; may be more appropriate. Anyway what it does is it continously increments time by one second (1000 msec) due to a pause of 1 second as in the setInterval function programmed. When as in your case you go to frame 7 to see the result the timer will stop.
    Actually I designed based on this a timer where you can also see the score and min + sec. You can start and stop manually or automatically. I can post the file tonight if you like. It's very easy to set up including the score (one and two player possible).

    Hope that helps
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  9. #9
    Senior Member
    Join Date
    Apr 2002
    Posts
    113
    Thanks!!! Please post it.

  10. #10
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Ok here it is. Please tell me any bugs or so. Check the individual action frames how to add the score and so on. I will write some tutorial on this later.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  11. #11
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Hi, it's me once more. This thread has inspired me to make a gametimer component, relatively easy to set up. Instructions are in the component script. The timer has also countdown option. It is a beta version and I have not tested it yet with a real game. Let me know how to improve (if you don't mind )
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  12. #12
    Senior Member
    Join Date
    Apr 2002
    Posts
    113
    Thanks again. I let you know if I find anything. I really appreciate your help.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center