5 Replies Latest reply on Apr 15, 2012 1:59 PM by Ned Murphy

    change the location of an array element (Animation)





      our teacher asked us to do a class project with Flash and I decide to do a demonstration for the different kinds of sorts and for that I need to show this procedure step by step:
      1 - compare two elements of the table
      2 - exchange their location in case of verification of the condition

      yet I managed to create a table and fill it with random number i alos did the exchange of the two first elements

      here is the code :



      var tab:Array = new Array();

      var min = 0;

      var max = 10;


      function remplir(tab) {

          for (i=0; i<5; i++) {

              tab[i] = Math.floor(Math.random()*(max-min+1))+min;





      t0 = tab[0];

      t1 = tab[1];

      t2 = tab[2];

      t3 = tab[3];

      t4 = tab[4];

      //t0,t1,t2,t4 are the dynamic text variable 

      var speed = 5;


      function deplacer(a, b, c, d, p) {

          if (a>b) {

              c._x += speed;

              d._x -= speed;

              if (d._x == p) {

                  speed = 0;




      onEnterFrame = function () {

          deplacer(t0, t1, to0, to1, 54);

      //to0 and to1 are the Instance Name of the Dynamic Texts 



      my problem is how to do this for the other Table elements (they are 5 elements)

      i mean i can't just create a for loop and replace to0 by to[i]

      (i don't know if that possible or not but i try it and it didn't work)


      Thank you