Skip navigation
Currently Being Moderated

change the location of an array element (Animation)

Apr 14, 2012 10:02 AM

Tags: #sort #table #array #table_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

  • Currently Being Moderated
    Apr 14, 2012 10:15 AM   in reply to alaStickman

    You are right to be thinking in terms of loops, so keep that in your thought process and keep trying.


    HAving someone here provide the answer for you doesn't help you at all except maybe to get a good grade for the project (until you are asked to explain it).

    Mark as:
  • Currently Being Moderated
    Apr 15, 2012 7:46 AM   in reply to alaStickman

    To target an object using a counter, you use still use the brackets but what you put in the brackets should be a string value for the instance name of the object...


    this["to"+i]  will target the to1 textfield when i = 1, etc

    Mark as:
  • Currently Being Moderated
    Apr 15, 2012 1:59 PM   in reply to alaStickman

    You're welcome

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points