PDA

View Full Version : Running many intervals at the same time


VictoriaWelby
07-03-2007, 03:42 AM
Hello,

I've been wanting to run several intervals at the same time. I've managed to do it, but when more than one is running at the same time, all the intervals' paces decrease. Here is the code:
//pour lancer le défilement des textes lors du clic
degre2_mc.onRelease = function ():Void {
//pour s'assuer qu'il y a des éléments dans le tableau (sinon, le tableau reconstruit dans deplacement contient des vides)
if (tableau2.length > 0) {
//choisir un élément du tableau au hasard
texteHasard = Math.floor(Math.random() * tableau2.length);
//trace("nombre du texte au hasard : " + texteHasard);
//définir la variable avec l'élément du tableau
texteChoisi = _root["tableau2"][texteHasard];
trace("nom du texte choisi : " + texteChoisi);
//enlever l'élément du tableau
tableau2.splice(texteHasard, 1);
trace("tableau après le retrait du mc : " + tableau2);
//lancer l'intervalle pour déplacer le texte
_root["mouvement" + texteChoisi] = setInterval(deplacement, 7, texteChoisi);
trace("nom de l'intervalle : " + _root["mouvement" + texteChoisi]);
}// fin if (tableau1.length > 0)
};// fin degre1_mc.onRelease = function ():Void

//pour le déplacement des textes
deplacement = function (texteChoisi:MovieClip):Void {
//déplacement du mc
_root[texteChoisi]._x -= 1;
//rafraîchissement de l'écran
updateAfterEvent ();
//quand le mc a disparu à gauche de l'écran...
if (_root[texteChoisi]._x <= -10 - _root[texteChoisi]._width) {
_root[texteChoisi]._x = 600;
tableau2.push(texteChoisi);
trace("tableau avec élément ajouté : " + tableau1);
clearInterval (_root["mouvement" + texteChoisi]);
}//fin if (texteChoisi._x = 0 - texteChoisi._width)
};// fin deplacement = function ():Void

If anybody would have an idea of the problem... or a solution, I'd be most grateful! :^)

Thanks!

fauzira
07-03-2007, 04:33 AM
I want to help but dont understand your comment languange on AS :confused:

inhan
07-03-2007, 04:52 AM
Did you try not using updateAfterEvent function?

(...) Executing long, memory-intensive scripts during an interval causes delays.

VictoriaWelby
07-03-2007, 12:39 PM
Did you try not using updateAfterEvent function?

I just did, and it doesn't solve the problem. :-(

And I'm wondering about the quote from Documentation. What I gave is almost the entirety of my code (there are 5 more lines to begin with, to create arrays). Would that be considered a "long, memory-intensive script"?

Thank you for your suggestion!

VictoriaWelby
07-03-2007, 12:45 PM
I want to help but dont understand your comment languange on AS :confused:

Sorry, English is a second language for me. I am much more at ease in French, and therefore comment my code in French. But here is the scenario for the intervals. I've got a mc:
degre2_mc
to which are associated three other mc, which I want to move to the left when the first mc is clicked:
_root["mouvement" + texteChoisi] = setInterval(deplacement, 7, texteChoisi);

"deplacement" is the function associated with the intervals, it moves the movieclips, and gets them back to their initial position once they've disappeared from the screen.

Across all this, there is an array to identify the movieclips of texts. Whenever one movieclip is moving, it is removed from the array, and is therefore not available anymore. It is put back once it has gone through the screen.

Hoping that makes it clearer...

VictoriaWelby
07-04-2007, 12:13 AM
A friend of mine has suggested a solution that works quite well. It consists in running only one interval that loops through an array containing all the movieclips that need to be moved.