# setInterval() and object method

**URL:** <https://forum.kirupa.com/t/setinterval-and-object-method/16127>\
**Category:** Uncategorized\
**Created:** [March 21, 2003, 4:33am UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127 "2003-03-21T04:33:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![KazchiX](https://avatars.discourse-cdn.com/v4/letter/k/3e96dc/32.png) [@KazchiX](https://forum.kirupa.com/u/KazchiX)\
**Post date:** [March 21, 2003, 4:33am UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/1 "2003-03-21T04:33:00Z")

</div>

Hi all,

Is there any way I can execute object’s method using setInterval() without instantiating new instance? For example,

var newInstance = new baseObject();  
setInterval(newInstance.someMethod,100);

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 5:06am UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/2 "2003-03-21T05:06:49Z")

</div>

May I ask what you are trying to do? There might be an alternative way other than setInterval.

With setInterval you need to call a function. So you could define the instance name within a parameter of the function.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 5:41am UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/3 "2003-03-21T05:41:46Z")

</div>

Hi lostinbeta,

I was just trying to make a small preloader component which I will reuse here and there. I could use for loop or while loop to do the same thing but I thought it would be clearer to use setInterval method. My code goes something like this;

[AS]function Preloader(xPosition,yPosition,itsWidth,itsHeight){  
this.\_x = xPosition;  
this.\_y = yPosition;  
this.\_width = itsWidth;  
this.\_height = itsHeight;  
\_root.createEmptyMovieClip(“loader\_mc”,1);  
}  
Preloader.prototype.createPreloader = function(){  
loaded = \_root.getBytesLoaded();  
total = \_root.getBytesTotal();  
percent = Math.round( loaded/total );  
wide = (preload.\_width \* percent)/100;  
loader\_mc.beginFill(0x333333,100);  
loader\_mc.moveTo(this.\_x,this.\_y);  
loader\_mc.lineTo(wide+this.\_x,this.\_y);  
loader\_mc.lineTo(wide+this.\_x,this.\_height+this.\_y);  
loader\_mc.lineTo(this.\_x,this.\_height+this.\_y);  
loader\_mc.lineTo(this.\_x,this.\_y);  
loader\_mc.endFill();  
loader\_mc.clear();  
}  
var preload = new Preloader(100,100,200,3);  
setInterval(preload.createPreloader,50);  
/\*  
while(\_root.getBytesLoaded() \< \_root.getBytesTotal()){  
loaded = \_root.getBytesLoaded();  
total = \_root.getBytesTotal();  
percent = Math.round( loaded/total );  
wide = (preload.\_width \* percent)/100;  
preload.createPreloader(wide);  
}  
\*/  
[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 5:55am UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/4 "2003-03-21T05:55:45Z")

</div>

Oh man, you’re going all OOPy on me :-\ I shamefully admit I am 100% horrible at OOP.

But the thing is, you don’t really need OOP to do such a project. And you can easily use the onEnterFrame dynamic event handler instead of setInterval.

A prototype preloader like this has already been created, you can check it out in the Best of Kirupa section and use it as a base example.

[http://www.kirupaforum.com/forums/showthread.php?s=&threadid=6794](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=6794)

Im sorry I wasn’t much help, but I neglected to realize in your first post and by the title that this was OOP related. I can understand OOP reading it, but writing it for me is a completely different story. And that makes debugging it just as bad.

I feel crummy now ☹

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 6:12am UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/5 "2003-03-21T06:12:06Z")

</div>

Thanks lostinbeta,

I guess I was not that off the track. I havent programmed in OOP for a while so this is pretty challenge for me too. AS is so similar to Java which is my favorite but there exists subtle diference and that difference confuse me sometime. I’ll post my version of preloader as soon as it’s done.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 6:15am UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/6 "2003-03-21T06:15:35Z")

</div>

Oooohhh, Java, I always wanted to learn Java. I know Javascript, but thats like nothing…lol. I can’t OOP in that very well either. Im OOP illiterate I guess you can say, but I am self taught, so maybe thats why, I don’t know.

One tip I can actually debug with your code now is this…

Regular functions cannot use the “this” locator. That is prototype function specific, you will have to define the location statically, or as a parameter within your function… something like…

[AS]function Preloader(myMC, xPosition,yPosition,itsWidth,itsHeight){

```
    myMC._x = xPosition;
    myMC._y = yPosition;
    myMC._width = itsWidth;
    myMC._height = itsHeight;
    _root.createEmptyMovieClip("loader_mc",1);

```

}[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 6:19am UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/7 "2003-03-21T06:19:26Z")

</div>

Thats a good tip. Thanks:)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 6:24am UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/8 "2003-03-21T06:24:30Z")

</div>

No problem, glad I could help with something here …lol. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 6:26am UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/9 "2003-03-21T06:26:08Z")

</div>

OOP??? What’s OOP??? OOPs??? I am OOP hater… :evil:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 6:28am UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/10 "2003-03-21T06:28:50Z")

</div>

OOP can be useful, if you know what your doing. But I don’t, so I guess I am with you on that one Cyan :evil:

:trout: 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 6:36am UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/11 "2003-03-21T06:36:33Z")

</div>

Yup… I was totally lost and wasted ever since I saw pointer in C++… :evil:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 6:43am UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/12 "2003-03-21T06:43:59Z")

</div>

I dont like pointer either  
but C++ is ok. I hate C. C should be gone by now.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 7:05am UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/13 "2003-03-21T07:05:21Z")

</div>

Um… C is less confusing than C++… Better language for somebody with small brain like me… :evil:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 2:36pm UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/14 "2003-03-21T14:36:07Z")

</div>

well, maybe C’s confusing to me because I never built a complete system using C. I tried once but it seemed hard to reuse code so I quit. C++ and java did the pretty good job so I didnt care much about C. Now more and more languages are available to us. Php,AS,Brew… Do they ever stop creating new standard and just let us live a normal life? I like AS much better than C and C++ anyways.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 2:44pm UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/15 "2003-03-21T14:44:40Z")

</div>

> Do they ever stop creating new standard and just let us live a normal life?  
> I wish… :sigh: But then, if they do, life will be too boring… :beam:  
> I like AS much better than C and C++ anyways.  
> Ditto!!! Yet, I gotta add Lingo in front of AS…

Hehe… I can see that you are pretty much organized and well-prepared person just by going over the languages you like, and I see that I am totally opposite… Oh, well… I’ll survive… 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 5:19pm UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/16 "2003-03-21T17:19:49Z")

</div>

I like AS better than C and C++ too. Oh wait, I don’t know those, I want to learn C++ and Java though. But AS’s downfall is that it doesn’t process information very efficiently. Java seems to do a much better job. When using multiple mathematical equations it doesn’t take much for Flash to be too CPU intensive, but i’ve seen Java applets and programs that do so much more without being half as CPU intensive. So that is kind of a drag.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 6:09pm UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/17 "2003-03-21T18:09:28Z")

</div>

Hey lostinbeta,

Java used be a major CPU sucker and now its getting better and better. I dont even realize it’s run on the VM. AS will surely follow the same path. Until then, we just sharpen our brains to optimize code.

I’ve got the new question for you. It’s still object related so I won’t launch a new thread. I have a component of preloader here. It’s packed in one class with couple of useful methods. How could I use this as external object or something like API does? I dont want to put the code in every fla.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 9:03pm UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/18 "2003-03-21T21:03:46Z")

</div>

[flashcomponents.net](http://flashcomponents.net) put out a few VERY useful tutorials on how to create components. I haven’t really tried any of them, but I hear good things about them. Perhaps one of the tutorials lets you figure out how to install a component so you can select it from the components panel.

[http://www.flashcomponents.net/tutorials.cfm?nav=4](http://www.flashcomponents.net/tutorials.cfm?nav=4)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 9:16pm UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/19 "2003-03-21T21:16:34Z")

</div>

I sooo wish I had pointers in Flash ☹

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 21, 2003, 9:17pm UTC](https://forum.kirupa.com/t/setinterval-and-object-method/16127/20 "2003-03-21T21:17:53Z")

</div>

btw, for more on setInterval see  
[http://www.umbc.edu/interactive/flash/tutorials/setInterval.php](http://www.umbc.edu/interactive/flash/tutorials/setInterval.php)

[Next page](https://forum.kirupa.com/t/setinterval-and-object-method/16127.md?page=2)
