# Problem implementing setInterval in a prototype

**URL:** <https://forum.kirupa.com/t/problem-implementing-setinterval-in-a-prototype/136319>\
**Category:** Uncategorized\
**Created:** [February 3, 2005, 7:09pm UTC](https://forum.kirupa.com/t/problem-implementing-setinterval-in-a-prototype/136319 "2005-02-03T19:09:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sikelianos](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sikelianos](https://forum.kirupa.com/u/sikelianos)\
**Post date:** [February 3, 2005, 7:09pm UTC](https://forum.kirupa.com/t/problem-implementing-setinterval-in-a-prototype/136319/1 "2005-02-03T19:09:31Z")

</div>

Hi. I’m trying to write a prototype function that will use setInterval. The following script defines a simple movieclip prototype that traces the clip’s x position when called. The function works fine when called explicitly ( \_root.foo.trace\_x(); ), but does not when called by a loop.

There are three clips on the stage, their instance names are foo, man, and chu. I created an array so I could loop through and have each one run the trace\_x function once.

Here’s the code:

```auto
 
clips = Array('foo', 'man', 'chu');
num_clips = clips.length;
//
MovieClip.prototype.trace_x = function() {
	trace(this._x);
	clearInterval(this.click_timer);
};
//
for (i=0; i<num_clips; i++) {
	current_clip = clips*;
	delay = 1000 * (i + 1);
	_root[current_clip].trace_x_timer = setInterval(_root[current_clip].trace_x, 1000);
}

```

The output should be like this:  
123.45 (x value of foo clip, traced after 1 second)  
854.24 (x value of man clip, traced after 2 seconds)  
453.29 (x value of chu clip, traced after 3 seconds)

but instead, the output is “undefined” over and over and over.

An example .fla can be found at [http://rgcreative.com/transfer/prototype\_and\_setinterval.zip](http://rgcreative.com/transfer/prototype_and_setinterval.zip)

Thanks for any help!
