Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

<< Prev 5 | Next 5

Array - Unique

// This script was already posted, but with an error, so i corrected it
// The other script didnt split tree or more equal elements side by side
// like this: a = [1,1,1,1] returned a = [1,1]

// This script splits the equal elements from an array
// Usage: a = [1,1,1,1,1,1];
// a = a.unique();
// now a = [1];

Array.prototype.unique = function()
{
        for (i=0; i<this.length; i++) {
                for (j=0; j<this.length-i; j++) {
                        if (this[i] == this[i+j+1]) {
                                this.splice(i+j+1, 1);
                                j--;
                        }
                }
        }
        return this;
};

// Now its correct =]

Posted by: IanLiu | website http://www.ianliu.art.br/
array flipper
function flip (arr) {
        var tmp = new Array();
        L = arr.length;
        for (i=0; i<arr.length; i++) {
                tmp.push(arr[L-1]);
                L = L-1;
        }
        return tmp;
}
temp = new Array(5, 10, 15, 20, 25, 30, 35, 40);
temp = flip(temp);
trace (temp);

Posted by: Qutaibah Hamadah | website http://www.perspectiveq.com
Array movieclip in rows and columns clearScriptedVersion
on (release) {
        var maxNum = 10;
        var num = 1;
        for (a=1; a<=maxNum; a++) {
                for (b=1; b<=maxNum; b++) {
                        _root.ball.duplicateMovieClip("ball"+num, num);
                        _root["ball"+num]._x = a*50;
                        _root["ball"+num]._y = b*50;
                        num++;
                }
        }
}

Posted by: chiu | website http://www.sexliesandfairytales.net
Array movieclip in rows and colums
on (release) {
        aantal = 1;
        for (a=1; a<=kolom; a++) {
                for (b=1; b<=rij; b++) {
                        duplicateMovieClip (balletje, aantal, aantal);
                        setProperty (aantal, _x, a * 20);
                        setProperty (aantal, _y, b * 20);
                        aantal = aantal+1;
                }
        }
}

Posted by: Bart De Meyere | website http://users.pandora.be/bartdemeyere
Array String Search
arr = ["Apollo", "Bacchus", "Ianus", "Iupiter", "Mars", "Mercurius"];
Array.prototype.sucher = function(w) {
        trace(this);
        var resD = [];
        var resC = [];
        for (i in this) {
                if ((this[i].indexOf(w, 0) != -1)) {
                        resD.push(this[i]);
                        resC.push(i);
                }
        }
        if (resD.length == 0) {
                return (-1);
        } else {
                resC.shift();
                resC = resC.reverse();
                return (resC);
        }
};
trace(arr.sucher("us"));

Posted by: andi haas | website http://www.andihaas.de

<< Prev 5 | Next 5

Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.