# Tutorial photo gallery

**URL:** <https://forum.kirupa.com/t/tutorial-photo-gallery/14726>\
**Category:** Uncategorized\
**Created:** [March 2, 2003, 12:45am UTC](https://forum.kirupa.com/t/tutorial-photo-gallery/14726 "2003-03-02T00:45:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![chapster](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@chapster](https://forum.kirupa.com/u/chapster)\
**Post date:** [March 2, 2003, 12:45am UTC](https://forum.kirupa.com/t/tutorial-photo-gallery/14726/1 "2003-03-02T00:45:06Z")

</div>

Ok I have read through the tutorial on  
[[COLOR=red]Photo Gallery [/COLOR] ](http://www.kirupa.com/developer/mx/photogallery.htm)  
and this is the only part I do not understand

```auto

	this.pIndex = (this.pIndex+d)%this.pArray.length;
	if (this.pIndex<0) {
		this.pIndex += this.pArray.length;
	}

```

I never got how to work that modulo division operator.  
That whole section I am confused. I guess because I can’t vision how it works. Can someone explain this is detail and simple for stupid people like me.  
Thanks in advance

---

<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:** [March 2, 2003, 12:50am UTC](https://forum.kirupa.com/t/tutorial-photo-gallery/14726/2 "2003-03-02T00:50:08Z")

</div>

This thread should explain the modulo operator…

[http://www.kirupaforum.com/showthread.php?s=&threadid=7095](http://www.kirupaforum.com/showthread.php?s=&threadid=7095)

---

<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:** [March 2, 2003, 1:43am UTC](https://forum.kirupa.com/t/tutorial-photo-gallery/14726/3 "2003-03-02T01:43:07Z")

</div>

Hey thanks for that link but there is still something I am not getting.  
I did a little test.

```auto

function temp() {
	trace("MODUL0 : " +(a++)%20);
	trace("A : "+a);
}

```

so every time you click a button it trace this function.  
lets say:  
a=4 % 20  
this would be 5  
now the modulo operator takes the remainder of the result  
in this case there is no remainder.  
so how come when a=5 the trace for the modulo = 4  
I can see it working in the trace where  
a=1 trace=0  
a=2 trace=1  
a=3 trace=2  
and so on  
What am I not getting here.

---

<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:** [March 2, 2003, 4:18am UTC](https://forum.kirupa.com/t/tutorial-photo-gallery/14726/4 "2003-03-02T04:18:42Z")

</div>

4%20 is the remainder of 4 divided by 20.

What you want is the remainder of twenty divided by 4 (20%4). Which in actuality does return 0 😉

---

<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:** [March 2, 2003, 6:47pm UTC](https://forum.kirupa.com/t/tutorial-photo-gallery/14726/5 "2003-03-02T18:47:58Z")

</div>

Ok so that will return 4  
so then 5%20  
will return 4 as well  
but this shows in the trace as 5  
I’m still not getting it. Forgive me for be stupid but can you show how it reaches twenty through its math.  
ok lets make it easier  
say reaches 7. Thanks for your patience with this question

```auto

function temp() {
	trace("MODUL0 : " +(a++)%7);
	trace("A : "+a);
}

```

---

<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:** [March 2, 2003, 6:54pm UTC](https://forum.kirupa.com/t/tutorial-photo-gallery/14726/6 "2003-03-02T18:54:58Z")

</div>

You are still having it reversed.

In essense you are getting the remainder of a/7, but from what you are saying you want the remainder of 7/a.

Try this…

```php
function temp() {
	a++;
	trace("A : "+a);
	trace("MODUL0 : "+7%a);
}

```

This is what I get in the output for that…

> A : 1  
> MODUL0 : 0  
> A : 2  
> MODUL0 : 1  
> A : 3  
> MODUL0 : 1  
> A : 4  
> MODUL0 : 3  
> A : 5  
> MODUL0 : 2  
> A : 6  
> MODUL0 : 1  
> A : 7  
> MODUL0 : 0

Which is all correct.

---

<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:** [March 2, 2003, 7:18pm UTC](https://forum.kirupa.com/t/tutorial-photo-gallery/14726/7 "2003-03-02T19:18:01Z")

</div>

Ok I see that but here is what I get when I turn it the other way  
the way the % modulo works.

```auto

function temp() {
    a++;
    trace("A : "+a);
    trace("MODUL0 : "+a%7);
}

```

```auto

A : 1
MODUL0 : 1
A : 2
MODUL0 : 2
A : 3
MODUL0 : 3
A : 4
MODUL0 : 4
A : 5
MODUL0 : 5
A : 6
MODUL0 : 6
A : 7
MODUL0 : 0

```

Ok I take a calcalator and devide 7 into a  
1%7=7  
2%7=3.5  
3%7=2.3333333  
4%7=1.75  
5%7=1.4  
6%7=1.1666666  
7%7=1  
8%7=0.875

Now what I am not getting is how flash is working out its numbers.  
Ok I am starting to feel really stupid now I hope this will benfit someone else so I don’t feel so alone. Thanks for your help on this

---

<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:** [March 2, 2003, 7:24pm UTC](https://forum.kirupa.com/t/tutorial-photo-gallery/14726/8 "2003-03-02T19:24:03Z")

</div>

I don’t think it works because technically its not a valid equation.

num1 % num2

You use modulo to get the remainder of how many times num2 can go into num1. If num2 is bigger than num1, then it is not really valid because the number bigger and cannot go into num1 correctly.

So I think Flash gets confused here or something.

---

<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:** [March 2, 2003, 8:00pm UTC](https://forum.kirupa.com/t/tutorial-photo-gallery/14726/9 "2003-03-02T20:00:16Z")

</div>

Ok now I see it clearer when num1 gets up to larger number than num2.

example  
10%7 the remainder would be 3

this now makes sence  
Thank you for your patience.  
How else would you use this operator. or what other purpose could you use it for.  
I don’t have any other example than the one I have done here but in the world of flash how else can it help one.  
And thanks again for your patience with this question.

---

<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:** [March 3, 2003, 2:56am UTC](https://forum.kirupa.com/t/tutorial-photo-gallery/14726/10 "2003-03-03T02:56:22Z")

</div>

You know what… I actually very rarely use Modulo :-\

Whatever case you can think of that might involve you needing to know the remainder of two numbers you can use modulo for 😛

I don’t know exact situations. Sorry.

---

<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:** [March 3, 2003, 2:58am UTC](https://forum.kirupa.com/t/tutorial-photo-gallery/14726/11 "2003-03-03T02:58:44Z")

</div>

Not to worry maybe someone else can answer this question. You have been so helpful and patient. Thanks again.  
🙂
