1 Reply Latest reply on Jul 8, 2009 7:29 AM by kglad

    problem with a cicle

    pao69

      Hi, everybody. I've a problem with a cicle in flash cs4.

      I have created a function for charge 9 swf movie in random mode. The problem is that every cicle the memory fills and after a few cicle the movie slows.

      I need to reset the function, but I don't know how.

       

      This is the code:

       

       

      var origine:Array = new Array;
      var temp:Array = new Array;
      var r:Number = 1;

       

       

       

      for(var e:Number = 1; e < 10; e++ ) {
          origine[e] = e;
      }

       

      var estrazione:Array = new Array;
      var n:Number = 0;
      for(var i:Number = 0; i < origine.length; i++) {    
          var rand:Number = Math.abs(Math.random() * origine.length);
          estrazione.splice(n, 0, origine.splice(rand, 1));
          i--;
          n++;
      }
      for(i = 0; i < 10; i++) {
          if(estrazione[i] == 0) {
              estrazione[i] = 10;
          }
      }

       

      function carica():void {

       

          var imageRequest:URLRequest = new URLRequest("movie"+estrazione[r]+".swf");
          var imageLoader:Loader = new Loader();
          imageLoader.load(imageRequest);
          addChild(imageLoader);
      }

       

      carica();

       

      var slide:Timer = new Timer(5000);
      slide.addEventListener(TimerEvent.TIMER, slider);

       

      function slider(event:TimerEvent):void {
          r++;
          if(r >= 10) {
              r = 1;
          }
          carica();
      }
      slide.start();

       

       

      thanks in advance.

        • 1. Re: problem with a cicle
          kglad Adobe Community Professional & MVP
          try:

           

          var origine:Array = new Array;
          var temp:Array = new Array;
          var r:Number = 1;

           

           

           

          for(var e:Number = 1; e < 10; e++ ) {
              origine[e] = e;
          }

           

          var estrazione:Array = new Array;
          var n:Number = 0;
          for(var i:Number = 0; i < origine.length; i++) {    
              var rand:Number = Math.abs(Math.random() * origine.length);
              estrazione.splice(n, 0, origine.splice(rand, 1));
              i--;
              n++;
          }
          for(i = 0; i < 10; i++) {
              if(estrazione[i] == 0) {
                  estrazione[i] = 10;
              }
          }

           

          var imageLoader:Loader

          function carica():void {

           

              var imageRequest:URLRequest = new URLRequest("movie"+estrazione[r]+".swf");

          if(imageLoader!=null){

          removeChild(imageLoader);

          iomageLoader=null;

          }

             imageLoader = new Loader();
              imageLoader.load(imageRequest);
              addChild(imageLoader);
          }

           

          carica();

           

          var slide:Timer = new Timer(5000);
          slide.addEventListener(TimerEvent.TIMER, slider);

           

          function slider(event:TimerEvent):void {
              r++;
              if(r >= 10) {
                  r = 1;
              }
              carica();
          }
          slide.start();

           

           

          thanks in advance.