# Where to insert setInterval

**URL:** <https://forum.kirupa.com/t/where-to-insert-setinterval/331336>\
**Category:** Uncategorized\
**Created:** [July 9, 2013, 12:11pm UTC](https://forum.kirupa.com/t/where-to-insert-setinterval/331336 "2013-07-09T12:11:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![capdetrons](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@capdetrons](https://forum.kirupa.com/u/capdetrons)\
**Post date:** [July 9, 2013, 12:11pm UTC](https://forum.kirupa.com/t/where-to-insert-setinterval/331336/1 "2013-07-09T12:11:06Z")

</div>

[COLOR=#333333][FONT=Verdana]Hi,[/FONT][/COLOR]

[COLOR=#333333][FONT=Verdana]I’m trying to have this gallery run by itself but eventhough it works, it doesn’t load the pictures in the thumbnails when the trace gives me a right variable. Besides, I get more values than expected from it.[/FONT][/COLOR]

[COLOR=#333333][FONT=Verdana]The images are on boxes attached dynamically and the onPress handler works perfectly tracing one value at a time:

[/FONT][/COLOR]  
this.onPress = function():Void { temp = id; this.id = \_parent.box1.id; \_parent.box1.id = temp; \_parent.box1.targetBox.attachMovie("image - "+temp, "image - "+temp, getNextHighestDepth()); this.targetBox.attachMovie("image - "+id, "image - "+id, getNextHighestDepth()); \_parent.box1.boxMask.\_width = \_parent.box1.targetBox.\_width; \_parent.box1.boxMask.\_height = \_parent.box1.targetBox.\_height; \_parent.box1.boxOutline.\_width = \_parent.box1.targetBox.\_width; \_parent.box1.boxOutline.\_height = \_parent.box1.targetBox.\_height; \_parent.box1.swapDepths(this);}[COLOR=#333333][FONT=Verdana]  
[/FONT][/COLOR][COLOR=#333333][FONT=Verdana]but if I changge the code to:

[/FONT][/COLOR]  
function swapImages():Void { id–; temp = id; trace("temp = "+temp); id = \_parent.box1.id; trace("id = "+id); \_parent.box1.id = temp; \_parent.box1.targetBox.attachMovie("image - "+temp, "image - "+temp, getNextHighestDepth()); this.targetBox.attachMovie("image - "+id, "image - "+id, getNextHighestDepth()); \_parent.box1.swapDepths(this); \_parent.box1.boxMask.\_width = \_parent.box1.targetBox.\_width; \_parent.box1.boxMask.\_height = \_parent.box1.targetBox.\_height; \_parent.box1.boxOutline.\_width = \_parent.box1.targetBox.\_width; \_parent.box1.boxOutline.\_height = \_parent.box1.targetBox.\_height; if(id == 0){ clearInterval(interval\_id); trace(“Interval cleared”); } } var interval\_id:Number = setInterval(swapImages, 2000);[COLOR=#333333][FONT=Verdana]

[/FONT][/COLOR][COLOR=#333333][FONT=Verdana]it will work but only on the main image tracing the values of all the clips.[/FONT][/COLOR]

[COLOR=#333333][FONT=Verdana]Any ideas of how to face this? If you open up the attached fla, comment the first part of the code and uncomment the end part of it.[/FONT][/COLOR]
