# \[CS3 AS2\] Alternate Mainloop?

**URL:** <https://forum.kirupa.com/t/cs3-as2-alternate-mainloop/254795>\
**Category:** flash\
**Created:** [March 15, 2008, 3:08pm UTC](https://forum.kirupa.com/t/cs3-as2-alternate-mainloop/254795 "2008-03-15T15:08:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArcadeJunky](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@ArcadeJunky](https://forum.kirupa.com/u/ArcadeJunky)\
**Post date:** [March 15, 2008, 3:08pm UTC](https://forum.kirupa.com/t/cs3-as2-alternate-mainloop/254795/1 "2008-03-15T15:08:33Z")

</div>

Hello! Exciting to be able to ask some questions of some experts.

I’m working on my 3rd game, which happens to be my first platform game, and I have a general question that I haven’t been able to find a good answer to so far.

My games are exclusively code-based. No frames, no timelines, no gotoandplay, just pure AS2. I use pure code because I’m a programmer, and I’m stuck with AS2 because I need my game to submit a score to server at the end, and only have AS2-version of the score submit logic (plus I don’t know AS3).

I have a single movie clip which serves as the holder for the game logic:

```auto

onClipEvent(load)
{
  // InitializeEverything
}

 
onClipEvent(enterFrame)
{
    function leveldone()
    {
         timeleft = _root.timeleft;
        
        for (i= timeleft; i > 0; i--)
        {
            _root.timeleft--;
            _root.score += 10;
           // force screen update here ????
        }
    }

     // the MainLoop: ProcessEverything...

}

```

Everything is going pretty well with the game, the basic logic is all done. Now, when the player reaches the end of a level I call a support function called leveldone(). And one of the things that I would like to happen inside of this function is have the seconds remaining on the level’s countdown timer to be converted into bonus points. No problem so far.

But, what I would like to have happen is something like you might see in a Mario game, where you actually see the timer value quickly counting down, while the score correspondingly quickly counts up over a period of a few seconds.

I can add the code which does the countup/countdown, but obviously the screen is not updating each time I tweak the dynamic text, so only the final result is seen. If there was a function I could put inside my countup/countdown loop that would force the screen to be updated with the latest values of the score and the timer it would be perfect. But I’m not aware of such a function.

Now, I guess I could code up a special state inside the MainLoop that would handle this countup/countdown when a flag was set, but I would prefer to have the countdown/countup logic in a separate temporary mainloop, if possible. If I could somehow achieve this, it would allow me to also save checking a flag inside the MainLoop.

I remember from programming in X-Windows and Motif Widgets on UNIX that this was possible. You could at any point in the execution of the normal mainloop, setup a secondary mainloop that processed different events with some code like this:

while (specialLoop)  
{  
event = XGetNextEvent();  
SpecialProcessEvent(event);  
}

Does anybody have any suggestions, how, in completely AS2-based program, I can do something along these lines?

1. Either force a screen update while still processing within the MainLoop, or…

2. Branch off to a secondary MainLoop, do some stuff, then return to the MainLoop without having to check a new flag in each iteration of the primary MainLoop?
