# Could somone explain it to me?

**URL:** <https://forum.kirupa.com/t/could-somone-explain-it-to-me/102198>\
**Category:** Uncategorized\
**Created:** [February 20, 2004, 7:43pm UTC](https://forum.kirupa.com/t/could-somone-explain-it-to-me/102198 "2004-02-20T19:43:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joaquin\_win](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Joaquin\_win](https://forum.kirupa.com/u/Joaquin_win)\
**Post date:** [February 20, 2004, 7:43pm UTC](https://forum.kirupa.com/t/could-somone-explain-it-to-me/102198/1 "2004-02-20T19:43:41Z")

</div>

MovieClip.prototype.changePhoto = function(d) {  
this.pIndex = (this.pIndex+d)%this.pArray.length;  
if (this.pIndex\<0) {  
this.pIndex += this.pArray.length;  
}  
this.onEnterFrame = fadeOut;  
};

Could someone be so kind and explain this to me…  
“pIndex” starts al zero (0)

and what the $&$% is “this.pArray.length”

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 20, 2004, 8:03pm UTC](https://forum.kirupa.com/t/could-somone-explain-it-to-me/102198/2 "2004-02-20T20:03:40Z")

</div>

I hope this explination will do… 😉

[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)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 22, 2004, 2:04am UTC](https://forum.kirupa.com/t/could-somone-explain-it-to-me/102198/3 "2004-02-22T02:04:35Z")

</div>

Thank you very much
