Home Tutorials Forums Articles Blogs Movies Library Employment Press
Home » Actionscripts library »  Array Object

Next 5

Basic array shuffler

function sortRand () {
        if (random(2) == 0) {
                return -1;
        }
        if (random(2) == 0) {
                return 1;
        }
}



array.sort(sortRand);

Posted by: khat | website http://www.webone.com.au/~khat/index.html
2d array from text file
/*this works for the MySecondaryArray having only exactly 3 fields.
i'm sure it could be done so that it adjusts automatically
but i didnt need it to so i didnt bother.
the text file goes like this :
myTextFileVar=this;;that::the next;;\n\nthis2;;that2:
:the next2;;\n\nthis3;;3that::3the next& where each "\n"
is a carrige return in the text file meaning there is
1 line between listed items to make it easier to use,
and "&" is the absolute last character to indicate the
end of the variable. if lost use trace actions to figure out what does what. enjoy.*/

_root.myConstuctor = new LoadVars();
_root.myConstuctor.load("MytextFile.txt");
_root.myConstuctor.onLoad = function(true) {
        if (true) {
                _root.myParsingVar1 = _root.myConstuctor.myTextFileVar;
                _root.myParsingArray = _root.myParsingVar1.split("\n\n");
                _root.myMainArray = new Array();
                for (j=0; j<_root.myParsingArray.length; j++) {
                        for (n=0; n<3; n++) {
                                _root.myParsingVar2 = _root.myParsingArray[j];
                                _root.mySecondaryArray = _root.myParsingVar2.split(";;");
                        }
                        _root.myMainArray[j] = _root.mySecondaryArray;
                }
        }
};

Posted by: mothh | website http://www.mothh.com
7 out off 49 Lottery
/*how to do a lottery? Draw 7 (unique) out off 49 balls for example */

pickfrom = new Array();
winlist = new Array();
all = 9;//49 easy to configure
shown = 7;//show 7 winner
for (i=0; i<all; i++) {
        pickfrom[i] = i+1;
}
trace("2003 by www.advance-media.com \nBegin: "+pickfrom);
for (i=0; i<shown; i++) {
        rand = Math.floor(Math.random()*(all-i));
        winlist[i] = pickfrom[rand];
        pickfrom.splice(rand, 1);
}
trace("Rest: "+pickfrom+"\nShow Winner: "+winlist);

/* I used it for loading 7 randomly picked movies
(holding nothing but pictures) out of 17 total and no repetition!
Each time the user clicks back to the site he gets to
see different pix on my slider bar....*/

Posted by: Folko Langner | website http://www.advance-media.com
a count
//count (a1+a2+---an)*(b1+b2+---bm)
//author:  tigerchina
k=0
Number.prototype.mu=function(a,b){
        for(i=0;i<a.length;i++){
                for(j=0;j<b.length;j++){
                        this=this+a[i] *b[j]
                }
        }return this
}
temp=new Number()
a=new Array(1,6)
b=new Array(3,4,7)
trace(temp.mu(a,b))

Posted by: tigerliao | website http://www.yahoo.com.cn
Add Values In Arrays V1
I developed this script to help o ut a Director user who wished to be able to perform operations like:
[10,10] + [5,-5] = [15, 5]
This function ads only. I thought of making it a prototype but then I thought better of it, as it's prolly more useful as a function for iterative applications, etc. Enough talk, here it is:
// Add values in arrays V1
// Jesse Stratford, www.actionscript.org
function arrayAdd (a, b) {
        tmp = new Array();
        // Math.max used to ensure no items are dropped
        // if one array is longer than the other
        for (var j = 0; j<Math.max(a.length, b.length); j++) {
                tmp[j] = a[j]+b[j];
        }
        return tmp;
}
// Usage Examples
answer = arrayAdd([10, 10], [5, -5]);
answer2 = arrayAdd([10, 10], [5, -5, 10]);
// Note answer2.length = 3

Posted by: Jesse Stratford | website http://www.actionscript.org

Next 5

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