RE: [Flashcoders] setInterval() and the trouble
Here is my sample code to demonstrate you the concept of setting interval (reset automatically if user fail to answer quiz in given time), interrupting interval and refreshing it (when user answer the quiz within given time, represented by onMouseDown event). Copy and paste all code into fresh FLA and test run it. If you don't click on the stage, the movie will refresh to next round in 3 secs unless you click on the stage to interrupt the timer, once you stop clicking, timer will go back to it's normal routine. [CODE] var timeFrame = 3000; // interval per question var count = 0; // counter onLoad = function(){ _root.createTextField("txt",10,10,10,50,20); setTimer(); } function setTimer(){ clearInterval(intIdle); intIdle = setInterval(nextRound, timeFrame); } // Kill timer permanently function killTimer(){ clearInterval(intIdle); } function nextRound(){ // actions you want to perform when time's up txt.text = "Round " + (count++); txt._x += 15; setTimer(); // reset new timer } onMouseDown=function(){ nextRound(); } [/CODE] [...] Sam Liu Flash Developer - Languages Online Office of Learning and Teaching Department of Education and Training T: (03) 9637 2102F: (03) 9637 2060 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Weyert de Boer Sent: Monday, 31 October 2005 9:36 AM To: Flashcoders mailing list Subject: Re: [Flashcoders] setInterval() and the trouble I got some stuff working now ;-=) Looks like I had some infinite loop indeed. Pff. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Important - This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education & Training. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] setInterval() and the trouble
I got some stuff working now ;-=) Looks like I had some infinite loop indeed. Pff. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] setInterval() and the trouble
One trick to use setInterval is to clear the interval ID every time you establish one regardless if the existence of the interval ID. This will make sure you still controlling the interval. If you establish setInterval more than one time to the sample Interval ID, the previous established interval is still running and you hardly clear it. Following codes only make minor change to yours. Whenever you want to reset your watch, you only need to call doStopwatch() function at anytime like what I did to your imaginary buildQuestion() function. But I am not sure what you try to do with this IF statement " if ( id >= questions.length ) " as it seems to create infinity looping when id >= question.length, unless you have simplified your function for this post to focus on setInterval thingies.. function doStopwatch() { // 1second = 1000ms clearInterval( _root.stopwatchIntervalId ); // ** _root.stopwatchIntervalId = setInterval( _root.stopwatchComplete, 3000 ); } function stopwatchComplete() { clearInterval( _root.stopwatchIntervalId ); // trigger the question completed method _root.questionComplete( _root.question.id, _root.question.type ); } function questionComplete( questionId, questionType ) { if ( id >= questions.length ) { // out of questions _root.stopwatchComplete(); } else { // next quesiton buildQuestion( questionId + 1 ); } } function buildQuestion( new_questionId ){ doStopWatch(); // ** // ... Your build question function code } If you need IDLE handling sample, I can sen you one [...] Sam Liu Flash Developer - Languages Online Office of Learning and Teaching Department of Education and Training T: (03) 9637 2102F: (03) 9637 2060 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Weyert de Boer Sent: Saturday, 29 October 2005 9:46 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] setInterval() and the trouble Hi Liam, First of all I always have had trouble with those methods, never got it right. Always failed, I don't they dont like! >I imagine you're calling clearInterval with the appropriate interval ID >upon each quiz question submittal, and then afterwards recalling >setInterval for the new question? How does it fail the second time? >Does it just never call it again, or does it call the function at a >different interval? > Well, I happen to have a resource xml file which get loaded prioer of each group of questions, once this group is readed a method in the root timeline gets triggered which will determine what to do. This method will also trigger the method buildQuestion() when required, this method will create a new instance of "question"-movieclip. After this part is done the function doStopwatch() is called: function doStopwatch() { // 1second = 1000ms _root.stopwatchIntervalId = setInterval( _root.stopwatchComplete, 3000 ); } function stopwatchComplete() { clearInterval( _root.stopwatchIntervalId ); // trigger the question completed method _root.questionComplete( _root.question.id, _root.question.type ); } function questionComplete( questionId, questionType ) { if ( id >= questions.length ) { // out of questions _root.stopwatchComplete(); } else { // next quesiton buildQuestion( questionId + 1 ); } } IF you have a better solution please let me know! I feel so stupid that I don't get thing timer stuff working. Yours, Weyert de Boer ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Important - This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education & Training. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] setInterval() and the trouble
perhaps it's liable to change On 30 Oct 2005, at 21:50, Derek Vadneau wrote: Actually, it's not documented. I remember reading about it at some point, but the local docs and livedocs do not have setTimeout, and it does not light-up for syntax highlighting. It works, but why this would not be documented is beyond me. Derek Vadneau -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steve Rankin Sent: Sunday, October 30, 2005 4:37 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] setInterval() and the trouble Not sure, but it's in the new ActionScript 2.0 Language Reference for Flash Player 8. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] setInterval() and the trouble
Actually, it's not documented. I remember reading about it at some point, but the local docs and livedocs do not have setTimeout, and it does not light-up for syntax highlighting. It works, but why this would not be documented is beyond me. Derek Vadneau -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steve Rankin Sent: Sunday, October 30, 2005 4:37 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] setInterval() and the trouble Not sure, but it's in the new ActionScript 2.0 Language Reference for Flash Player 8. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] setInterval() and the trouble
Not sure, but it's in the new ActionScript 2.0 Language Reference for Flash Player 8. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tim Beynart Sent: Sunday, October 30, 2005 2:59 PM To: Flashcoders mailing list Subject: RE: [Flashcoders] setInterval() and the trouble Why is something so useful undocumented? I have to bend over backwards to create single-fire timers. Thanks for the post. -Original Message- Its undocumented, but it works in a fire once kind of situation & like javascript: foo = setTimeout( func, ms) clearTimeout(foo) but only if you need to stop the interval. Otherwise, just fire it and forget it. e.d. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] setInterval() and the trouble
Why is something so useful undocumented? I have to bend over backwards to create single-fire timers. Thanks for the post. -Original Message- Its undocumented, but it works in a fire once kind of situation & like javascript: foo = setTimeout( func, ms) clearTimeout(foo) but only if you need to stop the interval. Otherwise, just fire it and forget it. e.d. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] setInterval() and the trouble
Its undocumented, but it works in a fire once kind of situation & like javascript: foo = setTimeout( func, ms) clearTimeout(foo) but only if you need to stop the interval. Otherwise, just fire it and forget it. e.d. On 10/30/05, Kent Humphrey <[EMAIL PROTECTED]> wrote: > Eric E. Dolecki wrote: > > use setTimeout now and you dont need to worry about interval ids. > > > > e.dolecki > > > > > > Have you found any documentation about setTimeout - because I haven't :< > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] setInterval() and the trouble
Eric E. Dolecki wrote: use setTimeout now and you dont need to worry about interval ids. e.dolecki Have you found any documentation about setTimeout - because I haven't :< ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] setInterval() and the trouble
use setTimeout now and you dont need to worry about interval ids. e.dolecki On Oct 29, 2005, at 11:21 AM, Weyert de Boer wrote: JOR wrote: At first glance it looks like you have a potential continuous loop issue? stopwatchComplete() >> questionComplete() >> stopwatchComplete() >> and so on if (id >= questions.length) Second is I don't see where "id" is defined in questionComplete() did you mean to type this instead: The id should ofcourse matched the correct name of the parameter. If you know a better way please let me know! if ( questionId >= questions.length ) Aha, good one I will try ;-) ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] setInterval() and the trouble
JOR wrote: At first glance it looks like you have a potential continuous loop issue? stopwatchComplete() >> questionComplete() >> stopwatchComplete() >> and so on if (id >= questions.length) Second is I don't see where "id" is defined in questionComplete() did you mean to type this instead: The id should ofcourse matched the correct name of the parameter. If you know a better way please let me know! if ( questionId >= questions.length ) Aha, good one I will try ;-) ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] setInterval() and the trouble
At first glance it looks like you have a potential continuous loop issue? stopwatchComplete() >> questionComplete() >> stopwatchComplete() >> and so on if (id >= questions.length) Second is I don't see where "id" is defined in questionComplete() did you mean to type this instead: if ( questionId >= questions.length ) JOR ___ === James O'Reilly === === SynergyMedia, Inc. === www.synergymedia.net Weyert de Boer wrote: Hi Liam, First of all I always have had trouble with those methods, never got it right. Always failed, I don't they dont like! I imagine you're calling clearInterval with the appropriate interval ID upon each quiz question submittal, and then afterwards recalling setInterval for the new question? How does it fail the second time? Does it just never call it again, or does it call the function at a different interval? Well, I happen to have a resource xml file which get loaded prioer of each group of questions, once this group is readed a method in the root timeline gets triggered which will determine what to do. This method will also trigger the method buildQuestion() when required, this method will create a new instance of "question"-movieclip. After this part is done the function doStopwatch() is called: function doStopwatch() { // 1second = 1000ms _root.stopwatchIntervalId = setInterval( _root.stopwatchComplete, 3000 ); } function stopwatchComplete() { clearInterval( _root.stopwatchIntervalId ); // trigger the question completed method _root.questionComplete( _root.question.id, _root.question.type ); } function questionComplete( questionId, questionType ) { if ( id >= questions.length ) { // out of questions _root.stopwatchComplete(); } else { // next quesiton buildQuestion( questionId + 1 ); } } IF you have a better solution please let me know! I feel so stupid that I don't get thing timer stuff working. Yours, Weyert de Boer ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] setInterval() and the trouble
Hi Liam, First of all I always have had trouble with those methods, never got it right. Always failed, I don't they dont like! I imagine you're calling clearInterval with the appropriate interval ID upon each quiz question submittal, and then afterwards recalling setInterval for the new question? How does it fail the second time? Does it just never call it again, or does it call the function at a different interval? Well, I happen to have a resource xml file which get loaded prioer of each group of questions, once this group is readed a method in the root timeline gets triggered which will determine what to do. This method will also trigger the method buildQuestion() when required, this method will create a new instance of "question"-movieclip. After this part is done the function doStopwatch() is called: function doStopwatch() { // 1second = 1000ms _root.stopwatchIntervalId = setInterval( _root.stopwatchComplete, 3000 ); } function stopwatchComplete() { clearInterval( _root.stopwatchIntervalId ); // trigger the question completed method _root.questionComplete( _root.question.id, _root.question.type ); } function questionComplete( questionId, questionType ) { if ( id >= questions.length ) { // out of questions _root.stopwatchComplete(); } else { // next quesiton buildQuestion( questionId + 1 ); } } IF you have a better solution please let me know! I feel so stupid that I don't get thing timer stuff working. Yours, Weyert de Boer ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] setInterval() and the trouble
I imagine you're calling clearInterval with the appropriate interval ID upon each quiz question submittal, and then afterwards recalling setInterval for the new question? How does it fail the second time? Does it just never call it again, or does it call the function at a different interval? Liam On 10/29/05, Weyert de Boer <[EMAIL PROTECTED]> wrote: > > Hmm, I am currently working on the "good" version of the quiz only I > have a question how I should implementate some part. The quiz should ask > yes/no questions and the user should only have three to six seconds to > answer the question. If the user fails to answer the question within > this time, the answer should be fault. Currently I used a setInterval() > with 3000ms only I never get stuff with intervals right. Always it goes > all fine the first question, but the second it fals. Does anyone know a > good way to implementate this? Maybe through event delegation instead of > a interval callback method? > > Yours, > > Weyert de Boer > ___ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders