# Simple function and setInterval not working

**URL:** https://forum.kirupa.com/t/simple-function-and-setinterval-not-working/182871
**Category:** flash
**Created:** [March 22, 2006, 3:51am UTC](https://forum.kirupa.com/t/simple-function-and-setinterval-not-working/182871 "2006-03-22T03:51:44Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![11113](https://avatars.discourse-cdn.com/v4/letter/1/e9c0ed/32.png) [@11113](https://forum.kirupa.com/u/11113)
#### Post date: [March 22, 2006, 3:51am UTC](https://forum.kirupa.com/t/simple-function-and-setinterval-not-working/182871/1 "2006-03-22T03:51:44Z")

</div>

Here is my code, i’ve tried searching the forums and fighting with this way of fading the movie clip in and out. The movie clip has an instance name of “box”:hitman:, my brother also can’t figure it out. need help!

```auto

[COLOR=Blue]var[/COLOR] fadeChecker:[COLOR=Blue]Boolean[/COLOR] = [COLOR=Blue]true[/COLOR];

[COLOR=Blue]function[/COLOR] flicker():[COLOR=Blue]Void[/COLOR]{
    [COLOR=Blue]if[/COLOR](box.[COLOR=Blue]_alpha[/COLOR] >= 100){
        fadeChecker = [COLOR=Blue]true[/COLOR];
    }
    [COLOR=Blue]else if[/COLOR](box.[COLOR=Blue]_alpha[/COLOR] <= 0){
        fadeChecker = [COLOR=Blue]false[/COLOR];
    }
   [COLOR=Blue] if[/COLOR](fadeChecker == [COLOR=Blue]true[/COLOR]){
        box.[COLOR=Blue]_alpha--[/COLOR];
    }
    [COLOR=Blue]else if[/COLOR](fadeChecker == [COLOR=Blue]false[/COLOR]){
        box.[COLOR=Blue]_alpha[/COLOR]++;
    }
} 
[COLOR=Blue]var [/COLOR]nInterval:[COLOR=Blue]Number[/COLOR] = [COLOR=Blue]setInterval[/COLOR](flicker,1000);

```

---

<div class="post-metadata">

### Author: ![11113](https://avatars.discourse-cdn.com/v4/letter/1/e9c0ed/32.png) [@11113](https://forum.kirupa.com/u/11113)
#### Post date: [March 22, 2006, 4:22pm UTC](https://forum.kirupa.com/t/simple-function-and-setinterval-not-working/182871/2 "2006-03-22T16:22:05Z")

</div>

I got it working, the [COLOR=“Blue”]setInterval[/COLOR] was just too slow, it went put opacity down by 1% each second, that’s pretty slow.

Now that i have that solved. I would like to know if there is an easier way to fade out these images all from the same function. As you can tell, this function only works for one movieclip at a time.

---

<div class="post-metadata">

### Author: ![11113](https://avatars.discourse-cdn.com/v4/letter/1/e9c0ed/32.png) [@11113](https://forum.kirupa.com/u/11113)
#### Post date: [March 24, 2006, 2:22pm UTC](https://forum.kirupa.com/t/simple-function-and-setinterval-not-working/182871/3 "2006-03-24T14:22:01Z")

</div>

?

---

<div class="post-metadata">

### Author: ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)
#### Post date: [March 24, 2006, 3:42pm UTC](https://forum.kirupa.com/t/simple-function-and-setinterval-not-working/182871/4 "2006-03-24T15:42:32Z")

</div>

i would proably use the tween class on your previous code, It will gave a much better fade, plus you can use easing too:)

---

<div class="post-metadata">

### Author: ![11113](https://avatars.discourse-cdn.com/v4/letter/1/e9c0ed/32.png) [@11113](https://forum.kirupa.com/u/11113)
#### Post date: [March 24, 2006, 3:59pm UTC](https://forum.kirupa.com/t/simple-function-and-setinterval-not-working/182871/5 "2006-03-24T15:59:04Z")

</div>

Wow, that sounds interesting, there’s a tween class in actionscript? you can ease through script too! Can you elaborate!

---

<div class="post-metadata">

### Author: ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)
#### Post date: [March 24, 2006, 4:10pm UTC](https://forum.kirupa.com/t/simple-function-and-setinterval-not-working/182871/6 "2006-03-24T16:10:51Z")

</div>

I’ve got two options for you:

* * *

1. 

easing function:

```auto
mx.transitions.OnEnterFrameBeacon.init();
MovieClip.prototype.setOEFBD = function():Boolean {
 if (!this.__OEFBD) {
  this.__OEFBD = new Object();
  MovieClip.addListener(this.__OEFBD);
  this.__OEFBD._parent = this;
  AsBroadcaster.initialize(this.__OEFBD);
  this.__OEFBD.addListener(this);
  return true;
 }
 return false;
};
MovieClip.prototype.easeTo = function(p:String, t:Number, e:Number):Void {
 this.setOEFBD();
 this.__OEFBD.onEnterFrame = function():Void {
  this._parent[p] += (t - this._parent[p]) / e;
  if (Math.round(this._parent[p]) == t) {
   this.broadcastMessage("onEaseFinished");
   delete this.onEnterFrame;
  }
 };
};

```

usage:

```auto
//MovieClip.easeTo(property:String, target:Number, ease:Number):Void
mc.easeTo("_alpha", 0, 10);

```

* * *

1. 

easing function:

```auto
_global.Tween = mx.transitions.Tween;
MovieClip.prototype.easeTo = function(p:String, t:Number, d:Number):Void {
 new Tween(this, p, mx.transitions.easing.Regular.easeOut, this[p], t, d, false).onMotionFinished = function():Void {
  this.obj.onMotionFinished();
 };
};

```

usage:

```auto
//MovieClip.easeTo(property:String, target:Number, duration:Number):Void
mc.easeTo("_alpha", 0, 30);

```

* * *

The first one has a lot of extra code in it that may not be of use to you at this point in time, it’s basically the long form of the second one :hoser:
