Photogallery tut

[AS]
MovieClip.prototype.changePhoto = function(d) {
// make sure pIndex falls within pArray.length
this.pIndex = (this.pIndex+d)%this.pArray.length;
if (this.pIndex<0) {
this.pIndex += this.pArray.length;
}
this.onEnterFrame = fadeOut;
};
[/AS]

I was reading that code, and i udnerstand it apart from the bit which says:
this.pIndex = (this.pIndex+d)%this.pArray.length;

Does it mean pindex + the changePhoto function equals a percentage and this percentage equals to the pArray length!?
thx

% in flash is called modulo.

It gets the remainder of the second number divided into the first number.

So 4%2 will return 0 because there is no remainder, but 4%3 will return 1 because there is a remainder of 1. And 10%6 will return 4 because there is a remainder of 4 when you divide 10 by 6.

So if pIndex is equal to the remainder of pIndex+d divided by the amount of items in the pArray array.

not just in Flash lost. its modulo in most other programming languages too. :slight_smile:

Yeah I know… I don’t know why I said “in Flash” I was just going to leave it as “is called modulo”, but I guess I ended up typing the rest there… hmm… I think I need sleep.

yeah me too…

I got a big day ahead of me tomorrow.

g’nite boys and girls (and lost)

Haha score! I am my own gender!

oh ok i see, but whats the point of getting the pIndex or remainder thing in this case?

It tells you right here …

// make sure pIndex falls within pArray.length

:wink:

If I am correct (it’s 3am here, i’m a bit… uhh… beat so I could be wrong), what this does is allows the gallery to loop so that when the last image is reached and you hit next it goes back to the first image and starts over.

ooh, well now i have more questions :wink:

It says pIndex+d…and it says funcion (d) too, so wat is pIndex adding?!!

and another question…before this code it said pIndex = 0, and as you said in your last post the code said:
// make sure pIndex falls within pArray.length

so what does that really mean?! i’m bit confused andsorry if you’re sleepy :slight_smile:

d can be one of 2 values, -1, or 1, as is shown on the back and forward buttons of the gallery.

So it could be pIndex+1 or pIndex+(-1) (essentially pIndex-1), and as with the forward button, if you keep hitting back and reach the first image, the gallery shoots back to the last image and starts in an infinite pattern like that so you can never just “stop” at the end of the gallery, it just loops.

Arrays start counting at 0, so item1 is really at place 0. So pIndex starts at 0 which is the beginning of the gallery. So pIndex is first set to 0.

[edit]my array explanation might be lacking so heres an example…

myArray = [“item 1”, “item 2”, “item 3”]

“item 1” is in place 0, “item 2” is in place 1, and “item 3” is in place 2.

To call them individually it would be…

myArray[0] (returns “item 1”)
myArray[1] (returns “item 2”)
myArray[2] (returns “item 3”)

does that help anymore? [/edit]

o ok, but when were the -1 and 1 set? or are they always like that? otherwise i think i get the rest of the stuff thx for the help :slight_smile:

d is a parameter of the function. When you call the function you supply a value of 1 or -1. 1 goes forward, -1 goes back (which is done via that whole modulo equation). You set the number when you call the function, which in the case of the photo gallery tutorial it is on the buttons, or when the left and right keyboard buttons are pressed.

It will look something like changePhoto(1) or changePhoto(-1)

alrite everything is clear now :slight_smile: thx if i have more questions i’ll be back :slight_smile:

learned something new today…I had no idea you could make a gallery so easy:)

hmm i have one question.Ok i have the array but i don’t use back and forward,i use pics.So when i click on a pic i want to call an item from an array and not it’s position.Instead of myArray[0] i want to have the item itself.How am i supose to that?

don’t you just use like the [] brackets!? i’m not too sure actually i was just guessin :-\

never mind i got it.Instead of myArray[0] just say 0.
Call it a coincidence but i was just working at a photo gallery for a site;)=)

Well I don’t understand what you were trying to do, but congrats on fixing the problem, I really wasn’t up for trying to figure out a whole new gallery technique :hangover:

The example of the gallery we worked with here is Sbeeners Photo Gallery tutorial which can be found on kirupa.com, if you were interested (and if the link wasn’t posted here already)