1 Reply Latest reply on Jun 4, 2009 9:13 PM by kglad

    Variable Array or Matrix in ActionScript 2.0

    Thomas P

      Riddle me this batman,

       

      I have a number of .swf files (1,2,3...) I want to load into another .swf file (A). Simple. However, I want these .swf files (1,2,3...) to load independantly and only on days of the week are specified. Say 1 on a tuesday and friday, 2 on wed and friday and 3 every day of the week.

       

      I was hoping I could establish a variable matrix or array in the (A) file such that it could look up the true or false values of each ad according to the day of the week.

       

      e.g.               File1     File2     File3     ....

                Sun     True     False     True

                Mon     False   Flase     True

                Tues    True     False     False

                .....

       

      Does anyone know the best way about this? Remembering, I'm not so picky about the array or matrix but I need to be able to load these files depending on the day and the variable that controls this needs to be easily accessible. And I'm not so keen on using XML either, unless that's the only practical solution.

       

      Thanks for any help you can offer!

       

      Cheers

        • 1. Re: Variable Array or Matrix in ActionScript 2.0
          kglad Adobe Community Professional & MVP

          create an array of arrays.  the first index will indicate the day (0,1,...,6) and that indexe's element will be the array of allowable swfs:

           


          var swfA:Array = [ [1,3], [3], [1],...[array of saturday's swf's] ];

           

          you can then use:

           

          var d:Date=new Date();

          var swfToLoad = shuffleF(swfA[d.getDay()]);

          yourTargetMC.loadMovie(swfToLoad);

           

          function shuffleF(a:Array):Array {
              n = a.length;
              while (n>1) {
                  k = Math.floor(Math.random()*n);
                  n--;
                  temp = a[n];
                  a[n] = a[k];
                  a[k] = temp;
              }
              return a;

          }