Archive for March, 2010




Flash Prototypes

Author: admin
March 2, 2010

Here’s two AS2 Flash prototypes that I use all the time. The search proto is probably from that genius sephiroth but I can’t remember since it’s been a while.  The shuffle prototype is from kingdavid.

Array Search Prototype

Array.prototype.search = function(needle, from, strict)
{
   if(from == undefined || from >= this.length) from = 0;
   strict = strict == undefined ? false : strict;
   for(var a = from; a < this.length; a++)
   {
      if(this[a] == needle)
      {
         if(strict)
         {
            if(this[a].__proto__ == needle.__proto__)
            {
               return a;
            }
         } else {
            return a;
         }
      }
   }
   return -1;
};

Array Shuffle Prototype

Array.prototype.shuffle = function() {
   var myArray = new Array();
   for (i=0; i<this.length; i++) {
      var control = true;
      while (control) {
         j = int(random(this.length));
         if (myArray[j] == undefined) {
            myArray[j] = this[i];
            control = false;
         }
      }
   }
   return myArray;
};