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 2102    F:  (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
[email protected]
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
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to