title: extending AS3's Array access operators to 'wrap' out-of-bound index values
body: <p>I'd really like to be able to make Flash's array access syntax 'wrap' over the array's bounds.</p>
  
  <p>Lengthy explanation - </p>
  
  <pre><code>var array:Array = ['a','b','c','d','e','f'];
  </code></pre>
  
  <p>To keep things simple, the first index is 0, and its value is the first letter, 'a'. To get that value, we'd do this -</p>
  
  <pre><code>array[0]; // returns 'a'
  </code></pre>
  
  <p>As long as the index you're using to access the array is between 0 and array.length (6 in our example,) everything works fine - but if you use an index outside of those bounds, you're shut down.</p>
  
  <pre><code>array[-3];
  array[9]; // both return 'undefined'
  </code></pre>
  
  <p>Sometimes that's a good thing - sometimes you expect that to happen, and you're fine with it. Other times, you find yourself wishing (or at least I find myself wishing) that it'd behave a bit more like this -</p>
  
  <pre><code>array[-3];
  array[9]; // both return 'd'
  </code></pre>
  
  <p>(e.g. a photo gallery that jumps back to the beginning when you click 'next' on the last photo)</p>
  
  <p>There's a little chunk of code I use over and over for this sort of thing, but it's always to alter the index <em>before</em> passing it into the array:</p>
  
  <pre><code>var index = -3;
  while(index &lt; 0){index += array.length}
  array[index % array.length]; // returns 'd'
  </code></pre>
  
  <p>... and that's fine, but what I really want to do is extend the Array object itself so that it'll automatically 'wrap' index values that go out of bounds.</p>
  
  <p>TL;DR - Is index-wrapping possible by extending Flash AS3's Array object?</p>