# Detecting the last "onMotionFinished" during loop

**URL:** https://forum.kirupa.com/t/detecting-the-last-onmotionfinished-during-loop/185519
**Category:** Uncategorized
**Created:** [April 13, 2006, 9:39pm UTC](https://forum.kirupa.com/t/detecting-the-last-onmotionfinished-during-loop/185519 "2006-04-13T21:39:49Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![dragonfly](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dragonfly](https://forum.kirupa.com/u/dragonfly)
#### Post date: [April 13, 2006, 9:39pm UTC](https://forum.kirupa.com/t/detecting-the-last-onmotionfinished-during-loop/185519/1 "2006-04-13T21:39:49Z")

</div>

let say i have an array (arr) that has references to 6 txt fields. I have a function like this:

```auto

function loopFadeAndCallFunction():Void {
    for (var i:Number = 0; i<arr.length; i++) {
        var txtTween:Tween = new Tween(arr*, "_alpha", mx.transitions.easing.Regular.easeOut, 0, 100, 0.5, true);
        txtTween.onMotionFinished = function() {
            doSomeFunction(); // but i only want this to be called on the sixth txtTween's ".onMotionFinished"
        };
    }
}

```

as commented, i only want the function “doSomeFunction” to execute on the final, sixth txtTween.onMotionFinished.

any ideas?

---

<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: [April 14, 2006, 12:03am UTC](https://forum.kirupa.com/t/detecting-the-last-onmotionfinished-during-loop/185519/2 "2006-04-14T00:03:43Z")

</div>

```auto
function loopFadeAndCallFunction():Void {
 for (var i:Number = 0; i < arr.length; i++) {
  var txtTween:Tween = new Tween(arr*, "_alpha", mx.transitions.easing.Regular.easeOut, 0, 100, 0.5, true);
 }
 txtTween.onMotionFinished = function() {
  doSomeFunction();
 };
}

```

---

<div class="post-metadata">

### Author: ![dragonfly](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dragonfly](https://forum.kirupa.com/u/dragonfly)
#### Post date: [April 14, 2006, 2:13am UTC](https://forum.kirupa.com/t/detecting-the-last-onmotionfinished-during-loop/185519/3 "2006-04-14T02:13:47Z")

</div>

Thanks for the reply Mr. Redleaf 🙂

I have to apologize as I don’t think my attempt at a simplified version of my script was adequate in explaining my problem. I pulled the following function out of my project and took out as much non-relevant stuff as i could.

The problem im haveing is that the user is able to click and activate my .onRelease function before all of the menu text has been created. This results in the possibility of text fields not being removed/hidden when the next animation begins, because they do not yet exist before the scipt that removes them is run (because it is run too early).

So I want to make sure that that the “cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]hit[/COLOR].[COLOR=#0000ff]enabled[/COLOR]” stays false until the last “cirBG\_txt” is faded to 100% alpha by the final “txtTween”.

If using any fundamentally poor techniques here (like nesting onMotionFinisheds?) please let me know.  
[AS]  
[FONT=Courier New][LEFT][COLOR=#000000] **function** [/COLOR] makeMenuNumCOLOR=#000000[/COLOR]:[COLOR=#0000ff]Void[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] menuHolder\_mc:[COLOR=#0000ff]MovieClip[/COLOR] = [COLOR=#0000ff]\_root[/COLOR].[COLOR=#0000ff]createEmptyMovieClip[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]“menuHolder”[/COLOR], menuHolderLevel[COLOR=#000000])[/COLOR];  
[COLOR=#000000] **var** [/COLOR] counter:[COLOR=#0000ff]Number[/COLOR] = [COLOR=#000080]1[/COLOR];  
[COLOR=#000000] **var** [/COLOR] circleCount:[COLOR=#0000ff]Number[/COLOR] = [COLOR=#000080]1[/COLOR];  
[COLOR=#000000] **var** [/COLOR] freq:[COLOR=#0000ff]Number[/COLOR] = [COLOR=#000080]2[/COLOR];  
[COLOR=#000000] **var** [/COLOR] totalCircles = [COLOR=#000080]6[/COLOR];  
[COLOR=#000000] **var** [/COLOR] cirIndex:[COLOR=#0000ff]Number[/COLOR] = [COLOR=#000080]0[/COLOR];  
menuHolder\_mc.[COLOR=#0000ff]\_y[/COLOR] = title\_txt.[COLOR=#0000ff]\_y[/COLOR]+title\_txt.[COLOR=#0000ff]\_height[/COLOR]+[COLOR=#000080]30[/COLOR];  
menuHolder\_mc.[COLOR=#0000ff]\_x[/COLOR] = [COLOR=#000080]26[/COLOR];  
[COLOR=#000000] **var** [/COLOR] menuBGHolder:[COLOR=#0000ff]MovieClip[/COLOR] = [COLOR=#0000ff]\_root[/COLOR].[COLOR=#0000ff]createEmptyMovieClip[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]“menuBGs”[/COLOR], menuBGHolderLevel[COLOR=#000000])[/COLOR];  
menuHolder\_mc.[COLOR=#0000ff]onEnterFrame[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]counter%freq == [COLOR=#000080]0[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] cir:[COLOR=#0000ff]MovieClip[/COLOR] = menuHolder\_mc.[COLOR=#0000ff]attachMovie[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]“circle”[/COLOR], [COLOR=#ff0000]“circle”[/COLOR]+circleCount, circleCount[COLOR=#000000])[/COLOR];  
cir.[COLOR=#0000ff]\_alpha[/COLOR] = [COLOR=#000080]0[/COLOR];  
[COLOR=#000000] **var** [/COLOR] cir\_txt:[COLOR=#0000ff]TextField[/COLOR] = cir.[COLOR=#0000ff]createTextField[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]“num\_txt”[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR][COLOR=#000000])[/COLOR];  
cir\_txt.[COLOR=#0000ff]\_alpha[/COLOR] = [COLOR=#000080]0[/COLOR];  
[COLOR=#000000] **var** [/COLOR] cirAlphaTween:Tween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]cir, [COLOR=#ff0000]"\_alpha"[/COLOR], mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]easing[/COLOR].[COLOR=#000080]Regular[/COLOR].[COLOR=#000080]easeOut[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]100[/COLOR], [COLOR=#000080]8[/COLOR], [COLOR=#000000] **false** [/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000] **var** [/COLOR] cirTxtAlphaTween:Tween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]cir\_txt, [COLOR=#ff0000]"\_alpha"[/COLOR], mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]easing[/COLOR].[COLOR=#000080]Strong[/COLOR].[COLOR=#000080]easeOut[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]100[/COLOR], [COLOR=#000080]0[/COLOR].[COLOR=#000080]5[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];  
cirAlphaTween.[COLOR=#000080]onMotionFinished[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] cirBG:[COLOR=#0000ff]MovieClip[/COLOR] = menuBGHolder.[COLOR=#0000ff]attachMovie[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]“bulletBG”[/COLOR], [COLOR=#ff0000]“bulletBG”[/COLOR]+cirIndex, cirIndex[COLOR=#000000])[/COLOR];  
cirBG.[COLOR=#000080]indexNum[/COLOR] = cirIndex;  
[COLOR=#000000] **var** [/COLOR] cirBG\_txt:[COLOR=#0000ff]TextField[/COLOR] = cirBG.[COLOR=#0000ff]createTextField[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]“bg\_txt”[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR][COLOR=#000000])[/COLOR];  
cirBG\_txt.[COLOR=#0000ff]\_alpha[/COLOR] = [COLOR=#000080]0[/COLOR];  
cirBG\_txt.[COLOR=#0000ff]text[/COLOR] = stepsXML.[COLOR=#0000ff]firstChild[/COLOR].[COLOR=#0000ff]childNodes[/COLOR][COLOR=#000000][[/COLOR]cirIndex[COLOR=#000000]][/COLOR].[COLOR=#0000ff]firstChild[/COLOR].[COLOR=#0000ff]firstChild[/COLOR].[COLOR=#0000ff]nodeValue[/COLOR];  
cirIndex++;  
[COLOR=#000000] **var** [/COLOR] txtTweenArr:[COLOR=#0000ff]Array[/COLOR] = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000ff]Array[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000] **var** [/COLOR] maskTween:Tween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]mask[/COLOR], [COLOR=#ff0000]"\_x"[/COLOR], mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]easing[/COLOR].[COLOR=#000080]Regular[/COLOR].[COLOR=#000080]easeOut[/COLOR], cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]mask[/COLOR].[COLOR=#0000ff]\_x[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR].[COLOR=#000080]5[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];  
maskTween.[COLOR=#000080]onMotionFinished[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] txtTween:Tween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]cirBG\_txt, [COLOR=#ff0000]"\_alpha"[/COLOR], mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]easing[/COLOR].[COLOR=#000080]Regular[/COLOR].[COLOR=#000080]easeOut[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]100[/COLOR], [COLOR=#000080]0[/COLOR].[COLOR=#000080]5[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];  
txtTweenArr.[COLOR=#0000ff]push[/COLOR]COLOR=#000000[/COLOR];  
cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]hit[/COLOR].[COLOR=#0000ff]onRollOver[/COLOR] = rollOverEffect;  
cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]hit[/COLOR].[COLOR=#0000ff]onRollOut[/COLOR] = cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]bgGrad[/COLOR].[COLOR=#0000ff]onDragOut[/COLOR]=rollOffEffect;  
cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]hit[/COLOR].[COLOR=#0000ff]onRelease[/COLOR] = transToFirstStep;  
cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]hit[/COLOR].[COLOR=#0000ff]enabled[/COLOR] = [COLOR=#000000] **false** [/COLOR];  
[COLOR=#808080]_//_[/COLOR]  
txtTween.[COLOR=#000080]onMotionFinished[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]hit[/COLOR].[COLOR=#0000ff]enabled[/COLOR] = [COLOR=#000000] **true** [/COLOR];  
[COLOR=#000000]}[/COLOR];  
[COLOR=#000000]}[/COLOR];  
[COLOR=#000000]}[/COLOR];  
[COLOR=#808080]_//_[/COLOR]  
circleCount++;  
[COLOR=#0000ff]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000ff]delete[/COLOR] menuHolder\_mc.[COLOR=#0000ff]onEnterFrame[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]  
counter++;  
[COLOR=#000000]}[/COLOR];  
[COLOR=#000000]}  
[/AS]  
[/COLOR] [/LEFT]  
[/FONT]

---

<div class="post-metadata">

### Author: ![dragonfly](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dragonfly](https://forum.kirupa.com/u/dragonfly)
#### Post date: [April 14, 2006, 2:15am UTC](https://forum.kirupa.com/t/detecting-the-last-onmotionfinished-during-loop/185519/4 "2006-04-14T02:15:02Z")

</div>

Thanks for the reply Mr. Redleaf 🙂

I have to apologize as I don’t think my attempt at a simplified version of my script was adequate in explaining my problem. I pulled the following function out of my project and took out as much non-relevant stuff as i could.

The problem im haveing is that the user is able to click and activate my .onRelease function before all of the menu text has been created. This results in the possibility of text fields not being removed/hidden when the next animation begins, because they do not yet exist before the scipt that removes them is run (because it is run too early).

So I want to make sure that that the “cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]hit[/COLOR].[COLOR=#0000FF]enabled[/COLOR]” stays false until the last “[COLOR=#000000][/COLOR]cirBG\_txt” is faded to 100% alpha by the final “txtTween”.

If using any fundamentally poor techniques here (like nesting onMotionFinisheds?) please let me know.

ActionScript Code:  
[FONT=Courier New][LEFT][COLOR=#000000] **function** [/COLOR] makeMenuNumCOLOR=#000000[/COLOR]:[COLOR=#0000FF]Void[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] menuHolder\_mc:[COLOR=#0000FF]MovieClip[/COLOR] = [COLOR=#0000FF]\_root[/COLOR].[COLOR=#0000FF]createEmptyMovieClip[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]“menuHolder”[/COLOR], menuHolderLevel[COLOR=#000000])[/COLOR];  
[COLOR=#000000] **var** [/COLOR] counter:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#000080]1[/COLOR];  
[COLOR=#000000] **var** [/COLOR] circleCount:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#000080]1[/COLOR];  
[COLOR=#000000] **var** [/COLOR] freq:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#000080]2[/COLOR];  
[COLOR=#000000] **var** [/COLOR] totalCircles = [COLOR=#000080]6[/COLOR];  
[COLOR=#000000] **var** [/COLOR] cirIndex:[COLOR=#0000FF]Number[/COLOR] = [COLOR=#000080]0[/COLOR];  
menuHolder\_mc.[COLOR=#0000FF]\_y[/COLOR] = title\_txt.[COLOR=#0000FF]\_y[/COLOR]+title\_txt.[COLOR=#0000FF]\_height[/COLOR]+[COLOR=#000080]30[/COLOR];  
menuHolder\_mc.[COLOR=#0000FF]\_x[/COLOR] = [COLOR=#000080]26[/COLOR];  
[COLOR=#000000] **var** [/COLOR] menuBGHolder:[COLOR=#0000FF]MovieClip[/COLOR] = [COLOR=#0000FF]\_root[/COLOR].[COLOR=#0000FF]createEmptyMovieClip[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]“menuBGs”[/COLOR], menuBGHolderLevel[COLOR=#000000])[/COLOR];  
menuHolder\_mc.[COLOR=#0000FF]onEnterFrame[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]if[/COLOR] [COLOR=#000000]([/COLOR]counter%freq == [COLOR=#000080]0[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] cir:[COLOR=#0000FF]MovieClip[/COLOR] = menuHolder\_mc.[COLOR=#0000FF]attachMovie[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]“circle”[/COLOR], [COLOR=#FF0000]“circle”[/COLOR]+circleCount, circleCount[COLOR=#000000])[/COLOR];  
cir.[COLOR=#0000FF]\_alpha[/COLOR] = [COLOR=#000080]0[/COLOR];  
[COLOR=#000000] **var** [/COLOR] cir\_txt:[COLOR=#0000FF]TextField[/COLOR] = cir.[COLOR=#0000FF]createTextField[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]“num\_txt”[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR][COLOR=#000000])[/COLOR];  
cir\_txt.[COLOR=#0000FF]\_alpha[/COLOR] = [COLOR=#000080]0[/COLOR];  
[COLOR=#000000] **var** [/COLOR] cirAlphaTween:Tween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]cir, [COLOR=#FF0000]"\_alpha"[/COLOR], mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]easing[/COLOR].[COLOR=#000080]Regular[/COLOR].[COLOR=#000080]easeOut[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]100[/COLOR], [COLOR=#000080]8[/COLOR], [COLOR=#000000] **false** [/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000] **var** [/COLOR] cirTxtAlphaTween:Tween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]cir\_txt, [COLOR=#FF0000]"\_alpha"[/COLOR], mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]easing[/COLOR].[COLOR=#000080]Strong[/COLOR].[COLOR=#000080]easeOut[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]100[/COLOR], [COLOR=#000080]0[/COLOR].[COLOR=#000080]5[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];  
cirAlphaTween.[COLOR=#000080]onMotionFinished[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] cirBG:[COLOR=#0000FF]MovieClip[/COLOR] = menuBGHolder.[COLOR=#0000FF]attachMovie[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]“bulletBG”[/COLOR], [COLOR=#FF0000]“bulletBG”[/COLOR]+cirIndex, cirIndex[COLOR=#000000])[/COLOR];  
cirBG.[COLOR=#000080]indexNum[/COLOR] = cirIndex;  
[COLOR=#000000] **var** [/COLOR] cirBG\_txt:[COLOR=#0000FF]TextField[/COLOR] = cirBG.[COLOR=#0000FF]createTextField[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]“bg\_txt”[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR][COLOR=#000000])[/COLOR];  
cirBG\_txt.[COLOR=#0000FF]\_alpha[/COLOR] = [COLOR=#000080]0[/COLOR];  
cirBG\_txt.[COLOR=#0000FF]text[/COLOR] = stepsXML.[COLOR=#0000FF]firstChild[/COLOR].[COLOR=#0000FF]childNodes[/COLOR][COLOR=#000000][[/COLOR]cirIndex[COLOR=#000000]][/COLOR].[COLOR=#0000FF]firstChild[/COLOR].[COLOR=#0000FF]firstChild[/COLOR].[COLOR=#0000FF]nodeValue[/COLOR];  
cirIndex++;  
[COLOR=#000000] **var** [/COLOR] txtTweenArr:[COLOR=#0000FF]Array[/COLOR] = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000FF]Array[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000] **var** [/COLOR] maskTween:Tween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]mask[/COLOR], [COLOR=#FF0000]"\_x"[/COLOR], mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]easing[/COLOR].[COLOR=#000080]Regular[/COLOR].[COLOR=#000080]easeOut[/COLOR], cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]mask[/COLOR].[COLOR=#0000FF]\_x[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]0[/COLOR].[COLOR=#000080]5[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];  
maskTween.[COLOR=#000080]onMotionFinished[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] txtTween:Tween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]cirBG\_txt, [COLOR=#FF0000]"\_alpha"[/COLOR], mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]easing[/COLOR].[COLOR=#000080]Regular[/COLOR].[COLOR=#000080]easeOut[/COLOR], [COLOR=#000080]0[/COLOR], [COLOR=#000080]100[/COLOR], [COLOR=#000080]0[/COLOR].[COLOR=#000080]5[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];  
txtTweenArr.[COLOR=#0000FF]push[/COLOR]COLOR=#000000[/COLOR];  
cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]hit[/COLOR].[COLOR=#0000FF]onRollOver[/COLOR] = rollOverEffect;  
cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]hit[/COLOR].[COLOR=#0000FF]onRollOut[/COLOR] = cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]bgGrad[/COLOR].[COLOR=#0000FF]onDragOut[/COLOR]=rollOffEffect;  
cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]hit[/COLOR].[COLOR=#0000FF]onRelease[/COLOR] = transToFirstStep;  
cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]hit[/COLOR].[COLOR=#0000FF]enabled[/COLOR] = [COLOR=#000000] **false** [/COLOR];  
[COLOR=#808080]_//_[/COLOR]  
txtTween.[COLOR=#000080]onMotionFinished[/COLOR] = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
cirBG.[COLOR=#000080]masked[/COLOR].[COLOR=#000080]hit[/COLOR].[COLOR=#0000FF]enabled[/COLOR] = [COLOR=#000000] **true** [/COLOR];  
[COLOR=#000000]}[/COLOR];  
[COLOR=#000000]}[/COLOR];  
[COLOR=#000000]}[/COLOR];  
[COLOR=#808080]_//_[/COLOR]  
circleCount++;  
[COLOR=#0000FF]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]delete[/COLOR] menuHolder\_mc.[COLOR=#0000FF]onEnterFrame[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]  
counter++;  
[COLOR=#000000]}[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[/LEFT]  
[/FONT]

---

<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: [April 14, 2006, 2:15am UTC](https://forum.kirupa.com/t/detecting-the-last-onmotionfinished-during-loop/185519/5 "2006-04-14T02:15:55Z")

</div>

:lol: I think your main problem is all of the HTML overwhelming your code - could you repost please?

---

<div class="post-metadata">

### Author: ![dragonfly](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dragonfly](https://forum.kirupa.com/u/dragonfly)
#### Post date: [April 14, 2006, 2:19am UTC](https://forum.kirupa.com/t/detecting-the-last-onmotionfinished-during-loop/185519/6 "2006-04-14T02:19:44Z")

</div>

hmm…

[AS]  
function makeMenuNum():Void {  
var menuHolder\_mc:MovieClip = \_root.createEmptyMovieClip(“menuHolder”, menuHolderLevel);  
var counter:Number = 1;  
var circleCount:Number = 1;  
var freq:Number = 2;  
var totalCircles = 6;  
var cirIndex:Number = 0;  
menuHolder\_mc.\_y = title\_txt.\_y+title\_txt.\_height+30;  
menuHolder\_mc.\_x = 26;  
var menuBGHolder:MovieClip = \_root.createEmptyMovieClip(“menuBGs”, menuBGHolderLevel);  
menuHolder\_mc.onEnterFrame = function() {  
if (counter%freq == 0) {  
var cir:MovieClip = menuHolder\_mc.attachMovie(“circle”, “circle”+circleCount, circleCount);  
cir.\_alpha = 0;  
var cir\_txt:TextField = cir.createTextField(“num\_txt”, 0, 0, 0, 0, 0);  
cir\_txt.\_alpha = 0;  
var cirAlphaTween:Tween = new Tween(cir, “\_alpha”, mx.transitions.easing.Regular.easeOut, 0, 100, 8, false);  
var cirTxtAlphaTween:Tween = new Tween(cir\_txt, “\_alpha”, mx.transitions.easing.Strong.easeOut, 0, 100, 0.5, true);  
cirAlphaTween.onMotionFinished = function() {  
var cirBG:MovieClip = menuBGHolder.attachMovie(“bulletBG”, “bulletBG”+cirIndex, cirIndex);  
cirBG.indexNum = cirIndex;  
var cirBG\_txt:TextField = cirBG.createTextField(“bg\_txt”, 0, 0, 0, 0, 0);  
cirBG\_txt.\_alpha = 0;  
cirBG\_txt.text = stepsXML.firstChild.childNodes[cirIndex].firstChild.firstChild.nodeValue;  
cirIndex++;  
var txtTweenArr:Array = new Array();  
var maskTween:Tween = new Tween(cirBG.masked.mask, “\_x”, mx.transitions.easing.Regular.easeOut, cirBG.masked.mask.\_x, 0, 0.5, true);  
maskTween.onMotionFinished = function() {  
var txtTween:Tween = new Tween(cirBG\_txt, “\_alpha”, mx.transitions.easing.Regular.easeOut, 0, 100, 0.5, true);  
txtTweenArr.push(txtTween);  
cirBG.masked.hit.onRollOver = rollOverEffect;  
cirBG.masked.hit.onRollOut = cirBG.masked.bgGrad.onDragOut=rollOffEffect;  
cirBG.masked.hit.onRelease = transToFirstStep;  
cirBG.masked.hit.enabled = false;  
//  
txtTween.onMotionFinished = function() {  
cirBG.masked.hit.enabled = true;  
};  
};  
};  
//  
circleCount++;  
if (circleCount\>totalCircles) {  
delete menuHolder\_mc.onEnterFrame;  
}  
}  
counter++;  
};  
}  
[/AS]

---

<div class="post-metadata">

### Author: ![dragonfly](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dragonfly](https://forum.kirupa.com/u/dragonfly)
#### Post date: [April 14, 2006, 2:21am UTC](https://forum.kirupa.com/t/detecting-the-last-onmotionfinished-during-loop/185519/7 "2006-04-14T02:21:13Z")

</div>

i dunno what the hell happened there. I tried to make it all neat and tidy with the AS tags, but after i previewed it, it got all wacked out with the html?

---

<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: [April 14, 2006, 2:36am UTC](https://forum.kirupa.com/t/detecting-the-last-onmotionfinished-during-loop/185519/8 "2006-04-14T02:36:30Z")

</div>

Ya there’s something funcky with VB 🙂

Anyways, give this a whirl:

```auto
import mx.transitions.Tween;
function makeMenuNum():Void {
 var menuHolder_mc:MovieClip = _root.createEmptyMovieClip("menuHolder", menuHolderLevel);
 var counter:Number = 1;
 var circleCount:Number = 1;
 var freq:Number = 2;
 var totalCircles = 6;
 var cirIndex:Number = 0;
 menuHolder_mc._y = title_txt._y + title_txt._height + 30;
 menuHolder_mc._x = 26;
 var menuBGHolder:MovieClip = _root.createEmptyMovieClip("menuBGs", menuBGHolderLevel);
 menuHolder_mc.onEnterFrame = function() {
  if (counter % freq == 0) {
   var cir:MovieClip = menuHolder_mc.attachMovie("circle", "circle" + circleCount, circleCount);
   cir._alpha = 0;
   var cir_txt:TextField = cir.createTextField("num_txt", 0, 0, 0, 0, 0);
   cir_txt._alpha = 0;
   var cirAlphaTween:Tween = new Tween(cir, "_alpha", mx.transitions.easing.Regular.easeOut, 0, 100, 8, false);
   var cirTxtAlphaTween:Tween = new Tween(cir_txt, "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, 0.5, true);
   cirAlphaTween.onMotionFinished = function() {
    var cirBG:MovieClip = menuBGHolder.attachMovie("bulletBG", "bulletBG" + cirIndex, cirIndex);
    cirBG.indexNum = cirIndex;
    var cirBG_txt:TextField = cirBG.createTextField("bg_txt", 0, 0, 0, 0, 0);
    cirBG_txt._alpha = 0;
    cirBG_txt.text = stepsXML.firstChild.childNodes[cirIndex].firstChild.firstChild.nodeValue;
    cirIndex++;
    var txtTweenArr:Array = new Array();
    var maskTween:Tween = new Tween(cirBG.masked.mask, "_x", mx.transitions.easing.Regular.easeOut, cirBG.masked.mask._x, 0, 0.5, true);
    maskTween.onMotionFinished = function() {
     var txtTween:Tween = new Tween(cirBG_txt, "_alpha", mx.transitions.easing.Regular.easeOut, 0, 100, 0.5, true);
     txtTweenArr.push(txtTween);
     cirBG.masked.hit.onRollOver = rollOverEffect;
     cirBG.masked.hit.onRollOut = cirBG.masked.bgGrad.onDragOut = rollOffEffect;
     cirBG.masked.hit.onRelease = transToFirstStep;
     cirBG.masked.hit.enabled = false;
     //
     if (circleCount == totalCircles) {
      txtTween.onMotionFinished = function() {
       cirBG.masked.hit.enabled = true;
      };
     }
    };
   };
   //
   circleCount++;
   if (circleCount > totalCircles) {
    delete menuHolder_mc.onEnterFrame;
   }
  }
  counter++;
 };
}

```

:?)

---

<div class="post-metadata">

### Author: ![dragonfly](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dragonfly](https://forum.kirupa.com/u/dragonfly)
#### Post date: [April 14, 2006, 1:11pm UTC](https://forum.kirupa.com/t/detecting-the-last-onmotionfinished-during-loop/185519/9 "2006-04-14T13:11:05Z")

</div>

Unless I over looked something it looks like you just added an if…then statement around the code that enables the buttons

```auto

...
if (circleCount == totalCircles) {
                        txtTween.onMotionFinished = function() {
                            trace("cirBG: "+cirBG);
                            cirBG.masked.hit.enabled = true;
                        };
                    }
...

```

This isn’t working though because the “circleCount” is counting up before even the first “maskTween.onMotionFinished” is finished. may be i need to make a dedicated counter just for the button enabling…hmmm

---

<div class="post-metadata">

### Author: ![dragonfly](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dragonfly](https://forum.kirupa.com/u/dragonfly)
#### Post date: [April 14, 2006, 2:43pm UTC](https://forum.kirupa.com/t/detecting-the-last-onmotionfinished-during-loop/185519/10 "2006-04-14T14:43:32Z")

</div>

dude, your’re right after all! i just need to replace the “==” with “\>”

as always, i appreciate the help from the North!
