# Set interval

**URL:** <https://forum.kirupa.com/t/set-interval/148446>\
**Category:** Uncategorized\
**Created:** [May 19, 2005, 9:56pm UTC](https://forum.kirupa.com/t/set-interval/148446 "2005-05-19T21:56:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thewebgremlin](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@thewebgremlin](https://forum.kirupa.com/u/thewebgremlin)\
**Post date:** [May 19, 2005, 9:56pm UTC](https://forum.kirupa.com/t/set-interval/148446/1 "2005-05-19T21:56:16Z")

</div>

Hi there,

I have an image gallery, which passes in three images ata time, and i have a load of gallery buttons which load pictures.

First of all, i work out how many gallewry buttons i need, by dividing the number if images by three, easy peasy.

Then what i need to do, is to loop through the gallery buttons from 0 to number of buttonsneeded, and fade each button in. i could tween this, but i wold like to script it. Simply using the code below, the loops are too fast, and the gallery buttons simply appear immediately

```auto
 
// i have just loaded in the images, and stored the number in this load vars object, kitchentext
 
this._parent.kitchentext.onLoad = function() {
  //hide all
  for (z=0; z<=6; z++) {
   _root["gallery"+z]._visible = false;
  }
  //get total number of images
  this.image_number = _root.kitchentext[_root.Currentkitchen+"_number"];
  this.gallerybuttons = this.image_number/3;
  //show gallery buttons needed
  for (i=0; i<=this.gallerybuttons; i++) {
   _root["gallery"+i]._alpha = 0;
   _root["gallery"+i]._visible = true;
   for (p=0; p<=100; p++) {
	_root["gallery"+i]._alpha += 1;
   }
  }
 };
 

```

So, i found the set interval fucntion, and came up with this

```auto
 
 
this._parent.kitchentext.onLoad = function() {
  //hide all
  for (z=0; z<=6; z++) {
   _root["gallery"+z]._visible = false;
  }
  //get total number of images
  this.image_number = _root.kitchentext[_root.Currentkitchen+"_number"];
  this.gallerybuttons = this.image_number/3;
  for (i=0; i<=this.gallerybuttons; i++) {
   //set gallery properties
   _root["gallery"+i]._alpha = 0;
   _root["gallery"+i]._visible = true;
   //create the function which increments gallery item alpha by 1
   increaseAlpha = function () {
	_root["gallery"+i]._alpha += 1;
	// if the galleries alpha = 100, break interval
	if (_root["gallery"+i]._alpha=100) {
	 clearInterval(Go);
	}
   };
   Go = setInterval(increaseAlpha, 10);
   //create interval to call fucntion every 10 milliseconds
  }
 };
 
 

```

This on in an on press event. (whether that makes any difference i dont know), and i cant seem to get it to work

Really greatful for any help on this, not long been using as 🙂

many thanks

jamie
