# Control looping

**URL:** <https://forum.kirupa.com/t/control-looping/266016>\
**Category:** flash\
**Created:** [July 15, 2008, 3:38pm UTC](https://forum.kirupa.com/t/control-looping/266016 "2008-07-15T15:38:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![DDD](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@DDD](https://forum.kirupa.com/u/DDD)\
**Post date:** [July 15, 2008, 3:38pm UTC](https://forum.kirupa.com/t/control-looping/266016/1 "2008-07-15T15:38:59Z")

</div>

I need a timeline to play only 3 times. I know it involves a counter of some sort. But not sure how to code that. Can someone kindly help out or point me to a resource?

Thanks

---

<div class="post-metadata">

**Author:** ![saxx](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@saxx](https://forum.kirupa.com/u/saxx)\
**Post date:** [July 15, 2008, 3:43pm UTC](https://forum.kirupa.com/t/control-looping/266016/2 "2008-07-15T15:43:37Z")

</div>

Wooo what i posted was completly retarded

_waits for senocular_

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [July 15, 2008, 4:02pm UTC](https://forum.kirupa.com/t/control-looping/266016/3 "2008-07-15T16:02:03Z")

</div>

Put this at the end of the timeline anim;

```auto

dispatchEvent(new Event("TIMELINE_DONE"));

```

Then just listen to that event.

```auto

var cnt:uint = 0;
TIMELINEOBJECT.addEventListener("TIMELINE_DONE", mo);

function mo(e:Event):void {
	cnt++;
	cnt > 2 ? e.target.stop() : null;
};

```

above example is with timeline code, so move it in to whatever class you are using. Timeline code is not awesome.

---

<div class="post-metadata">

**Author:** ![DDD](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@DDD](https://forum.kirupa.com/u/DDD)\
**Post date:** [July 15, 2008, 4:48pm UTC](https://forum.kirupa.com/t/control-looping/266016/4 "2008-07-15T16:48:09Z")

</div>

uuuhhh…hmmm…class…um yea…well…do not know how to use classes 😛  
This is just a flash ad banner. Is there anyway it can all be self contained in the flash file? Maybe on the timeline.

But thank you for the help thus far.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [July 15, 2008, 4:55pm UTC](https://forum.kirupa.com/t/control-looping/266016/5 "2008-07-15T16:55:14Z")

</div>

such a hard, simple question.

Throw this in the last frame of the timeline and it should work

```auto
var loopCount:int = 3; // how many times do you want to play?
var counter:int; // used by the if check to see how many times already played

counter++; // we're at the last frame so up the play counter
// now check to see if we need to stop
if (counter >= loopCount) stop();

```

The one thing to take note is that counter is not given an assigned value. Why not? because if you assign it a value, it will be set to that value every time this frame is entered. Instead we want it to continuously update when this frame is entered. So we’ll rely on the int type declaration to give the variable an initial value of 0 and then ++ it up from there.

There are ways to work around this… but just doing what I’ve done above makes it easy and compact.

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [July 15, 2008, 4:55pm UTC](https://forum.kirupa.com/t/control-looping/266016/6 "2008-07-15T16:55:49Z")

</div>

yeah dude, you can just use the code I pasted 😛

Here, I’ll attach a quick FLA example

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [July 15, 2008, 4:56pm UTC](https://forum.kirupa.com/t/control-looping/266016/7 "2008-07-15T16:56:35Z")

</div>

Oh the maaaain timeline… Sorry 😕 Thought you meant a timeline inside a child. 😕

---

<div class="post-metadata">

**Author:** ![DDD](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@DDD](https://forum.kirupa.com/u/DDD)\
**Post date:** [July 15, 2008, 5:25pm UTC](https://forum.kirupa.com/t/control-looping/266016/8 "2008-07-15T17:25:33Z")

</div>

You guys are my favs…thanks a bunch. I promise to learn AS by the time they get to AS5

---

<div class="post-metadata">

**Author:** ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)\
**Post date:** [July 15, 2008, 5:34pm UTC](https://forum.kirupa.com/t/control-looping/266016/9 "2008-07-15T17:34:36Z")

</div>

Sen that’s awesome - simple and easy to understand.  
[COLOR=“Gray”]  
_feels brain getting a little bit bigger_[/COLOR]
