# How to I run a code only ONCE when in a loop?

**URL:** <https://forum.kirupa.com/t/how-to-i-run-a-code-only-once-when-in-a-loop/253207>\
**Category:** flash\
**Created:** [February 28, 2008, 3:15am UTC](https://forum.kirupa.com/t/how-to-i-run-a-code-only-once-when-in-a-loop/253207 "2008-02-28T03:15:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andymac1990](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@andymac1990](https://forum.kirupa.com/u/andymac1990)\
**Post date:** [February 28, 2008, 3:15am UTC](https://forum.kirupa.com/t/how-to-i-run-a-code-only-once-when-in-a-loop/253207/1 "2008-02-28T03:15:27Z")

</div>

I don’t know how many times I have come a crossed this and I’m sure there is a simple solution to it but it’s just not coming to me. The most simple way I can think of right now uses a variable. If I could do this with out a variable, it would be amazing. Here is how I do it:

```auto

stage.addEventListener(Event.ENTER_FRAME, message);

var messageDone:Boolean = false;
function message(event:Event):void
    {
    ... other code ...

    if (!messageDone) 
        {
            trace("This message is only played once instead of once every frame");
            messageDone = true;
        }
    }

```

Also I was wondering if there is an eventHandler that triggers, for example, when the var messageDone == true ? Please, any advice would be much appreciated.:thumb2:
