# SetInterval help

**URL:** https://forum.kirupa.com/t/setinterval-help/185955
**Category:** flash
**Created:** [April 18, 2006, 1:33am UTC](https://forum.kirupa.com/t/setinterval-help/185955 "2006-04-18T01:33:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![floyd242](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@floyd242](https://forum.kirupa.com/u/floyd242)
#### Post date: [April 18, 2006, 1:33am UTC](https://forum.kirupa.com/t/setinterval-help/185955/1 "2006-04-18T01:33:50Z")

</div>

Hello,

I’m not sure if this is possible but I’m trying to fiqure out a way to have multiple SetInterval functions. what I’m trying to do is have text highlight a sentence using the setinterval function than after the number of chars needed are highlighted I want to be able to clear the interval and then start with the next sentence through another setInterval.

The program I’m trying to write is somewhat of a text to speech. I have a audio clip and a static text box. the audio is supposed to sync with the highlight of the text. the only way i could fiqure to generate the sync with a highlight was through setSelection as a loop.

I hope i’m making sense as this is my first post and I’m new to this type of actionscript.

here is where I am currently at.

```auto
var i:Number = 0;
var my_snap:TextSnapshot = test.getTextSnapshot();
var count:Number = my_snap.getCount()
my_snap.setSelectColor(0xffff00);

var intervalId:Number;
var count:Number = 0;
var count2:Number = 0;
var maxCount:Number = 20;
var maxCount2:Number = 113;
var duration:Number = 50;

var intervalId:Number;
var count:Number = 0;
var maxCount:Number = 20;
var duration:Number = 50;

function executeCallback():Void {
 trace("executeCallback intervalId: " + intervalId + " count: " + count);
 my_snap.setSelected(i, i+1 , true)
i++;
 if(count >= maxCount) {
 clearInterval(intervalId);
 my_snap.setSelected(0, 21 , false);
 clearInterval(intervalId);
 }
 count++;
}

function beginInterval():Void {
 if(intervalId != null) {
 trace("clearInterval");
 clearInterval(intervalId);
 }
 intervalId = setInterval(this, "executeCallback", duration);
}

function beginInterval2():Void {
 if(intervalId != null) {
 trace("clearInterval");
 clearInterval(intervalId);
 }
 intervalId = setInterval(this, "executeCallback", duration);
}

beginInterval();
beginInterval();

```

help

floyd

---

<div class="post-metadata">

### Author: ![floyd242](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@floyd242](https://forum.kirupa.com/u/floyd242)
#### Post date: [April 21, 2006, 5:41pm UTC](https://forum.kirupa.com/t/setinterval-help/185955/2 "2006-04-21T17:41:48Z")

</div>

bump

> [@floyd242](#):
>
> Hello,
> 
> I’m not sure if this is possible but I’m trying to fiqure out a way to have multiple SetInterval functions. what I’m trying to do is have text highlight a sentence using the setinterval function than after the number of chars needed are highlighted I want to be able to clear the interval and then start with the next sentence through another setInterval.
> 
> The program I’m trying to write is somewhat of a text to speech. I have a audio clip and a static text box. the audio is supposed to sync with the highlight of the text. the only way i could fiqure to generate the sync with a highlight was through setSelection as a loop.
> 
> I hope i’m making sense as this is my first post and I’m new to this type of actionscript.
> 
> here is where I am currently at.
> 
> ```auto
> var i:Number = 0;
> var my_snap:TextSnapshot = test.getTextSnapshot();
> var count:Number = my_snap.getCount()
> my_snap.setSelectColor(0xffff00);
> 
> var intervalId:Number;
> var count:Number = 0;
> var count2:Number = 0;
> var maxCount:Number = 20;
> var maxCount2:Number = 113;
> var duration:Number = 50;
> 
> var intervalId:Number;
> var count:Number = 0;
> var maxCount:Number = 20;
> var duration:Number = 50;
> 
> function executeCallback():Void {
> trace("executeCallback intervalId: " + intervalId + " count: " + count);
> my_snap.setSelected(i, i+1 , true)
> i++;
> if(count >= maxCount) {
> clearInterval(intervalId);
> my_snap.setSelected(0, 21 , false);
> clearInterval(intervalId);
> }
> count++;
> }
> 
> function beginInterval():Void {
> if(intervalId != null) {
> trace("clearInterval");
> clearInterval(intervalId);
> }
> intervalId = setInterval(this, "executeCallback", duration);
> }
> 
> function beginInterval2():Void {
> if(intervalId != null) {
> trace("clearInterval");
> clearInterval(intervalId);
> }
> intervalId = setInterval(this, "executeCallback", duration);
> }
> 
> beginInterval();
> beginInterval();
> 
> ```
> 
> help
> 
> floyd
