Skip to content

Instantly share code, notes, and snippets.

@renzocastro
Created February 27, 2010 04:21
Show Gist options
  • Save renzocastro/316472 to your computer and use it in GitHub Desktop.
Save renzocastro/316472 to your computer and use it in GitHub Desktop.
ActionScript: getFirstIndex Function (For Ranges)
/**
* For Ranges
*/
function getFirstIndex(indexSelected:Number, range:Number, total:Number):Number
{
var middle:Number = Math.ceil(range/2);
var index:Number;
if(indexSelected < middle)
index = 1;
else if( indexSelected > total - middle )
index = total - range + 1;
else
index = indexSelected - middle + 1;
return index;
}
trace( getFirstIndex(5,7,10) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment