1 Reply Latest reply on Oct 4, 2006 4:56 AM by coldMiner

    setInterval() / clearInterval()

      I'm working on an animation where movieclips are to fade in and out. This is to happen at the same time on several locations. I've use a setInterval/clearInterval, but the clearInterval does not work as i want it to. Here is my code:

      var i:Number = 0;
      var j:Number = 0;
      var count1:Number;
      var count2:Number;

      var Array:Array = new Array();
      var Array2:Array = new Array();
      var Array1:Array = new Array();

      function makeArray() {
      count1 = 1;
      count2 = 2;
      Array2[0] = mc1;
      Array2[1] = mc2;
      Array2[2] = mc3;
      Array2[0]._visible = true;
      Array2[1]._visible = false;
      Array2[2]._visible = false;
      Array2[0]._alpha = 100;

      Array1[0] = mc3;
      Array1[1] = mc2;
      Array1[2] = mc1;
      Array1[0]._visible = true;
      Array1[1]._visible = false;
      Array1[2]._visible = false;
      Array1[0]._alpha = 100;
      function fadeInNext(counter:Number, Array:Array,) {

      Array[0]._visible = true;
      Array[0]._alpha = 100;
      Array[1]._visible = true;
      Array[1]._alpha = 0;
      Array[0].fade(100, 5, Array[0]);
      Array[1].fade(0, 5, Array[1]);
      if (Array[0] != null) {
      } else {

      this.play.onRelease = function() {
      if (Array2[0] != null) {


      count1 = setInterval(fadeInNext, 4500, count1, Array1);
      count2 = setInterval(fadeInNext, 4500, count2, Array2);

      When i hit the play-button it works for the first run-through, but i want to user to be able to hit the play button while the animation is runing (and then the animation is to start at the beginning). This does work sometimes, but not all the time. I've not been able to understand why.

      Another problem is the clearInterval. It also works and stops at the first run through, but not after that. Then it keeps on going into the else (with clearInterval) in the fadeInNext-function. It does not stop.

      Can anyone out there help me with my problems? Thank you very much!! (i'm using mx2004)