[AS]
// create prototype (in this case a function that
// can be called from every movieclip, like myClip.changePhoto )
MovieClip.prototype.changePhoto = function(d) {
// % = modulo operator, which divides
// expression1 (pIndex+d) with expression 2 (pArray.length)
// and returns the remainder.
// For example: 7 % 3 would return 1.
// 7/3 = 2
// 2*3 = 6
// 7-6 = 1)
this.pIndex = (this.pIndex+d)%this.pArray.length;
// if pIndex is more than 0
if (this.pIndex<0) {
// add pArray.length to pIndex.
this.pIndex += this.pArray.length;
}
this.onEnterFrame = fadeOut;
};
[/AS]
pArray.length is the length of the array pArray. if the pArray contains two values, the length is two. if it contains five values, length is five and so on…
if you don’t call the function with a parameter, I assume pIndex will be zero at the beginning.
this will make pIndex = 1 at the beginning:
myClip.changePhoto(1);
also, see Flash help on the modulo operator: AS dictionary > Symbolic operators > % (modulo)