Tutorial photo gallery

Ok I have read through the tutorial on
[COLOR=red]Photo Gallery [/COLOR]
and this is the only part I do not understand



	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

This thread should explain the modulo operator…

http://www.kirupaforum.com/showthread.php?s=&threadid=7095

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


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.

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 :wink:

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


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

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…

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.

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


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



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

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.

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.

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 :stuck_out_tongue:

I don’t know exact situations. Sorry.

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