# Forcing code execution before moving on

**URL:** <https://forum.kirupa.com/t/forcing-code-execution-before-moving-on/25430>\
**Category:** flash\
**Created:** [July 12, 2003, 6:33pm UTC](https://forum.kirupa.com/t/forcing-code-execution-before-moving-on/25430 "2003-07-12T18:33:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danneman](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@Danneman](https://forum.kirupa.com/u/Danneman)\
**Post date:** [July 12, 2003, 6:33pm UTC](https://forum.kirupa.com/t/forcing-code-execution-before-moving-on/25430/1 "2003-07-12T18:33:41Z")

</div>

I am trying to set a couple of \_global variables with if-then statement, and just after this, use these \_globals in the code.

However, the code moves on before the \_globals are properly set.

How can I make the code wait (no timers, please) until the \_globals are set?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 12, 2003, 6:47pm UTC](https://forum.kirupa.com/t/forcing-code-execution-before-moving-on/25430/2 "2003-07-12T18:47:57Z")

</div>

```auto
if (_globals != undefined) {
// do yo thang
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 12, 2003, 6:55pm UTC](https://forum.kirupa.com/t/forcing-code-execution-before-moving-on/25430/3 "2003-07-12T18:55:47Z")

</div>

Thanks for the reply.

However, the globals change regularly and are always defined.  
How could I wait for a \_global to CHANGE its current value?

I could probably undefine them first, and then define them again, and thus use this code.  
But since undefining a \_global also takes time, the code could move on before it is undefined and use the old value.

Any ideas?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 12, 2003, 8:45pm UTC](https://forum.kirupa.com/t/forcing-code-execution-before-moving-on/25430/4 "2003-07-12T20:45:24Z")

</div>

Difficult one, huh? What a screwed up problem - Im pretty sure AS is the only programminglanguage that lets the code continue without having set the variables first _LOOOL_

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 12, 2003, 9:24pm UTC](https://forum.kirupa.com/t/forcing-code-execution-before-moving-on/25430/5 "2003-07-12T21:24:23Z")

</div>

did you trace() them to check? shouldn’t happen…?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 13, 2003, 6:34pm UTC](https://forum.kirupa.com/t/forcing-code-execution-before-moving-on/25430/6 "2003-07-13T18:34:55Z")

</div>

Yep, _puh_ I dont think Ive ever done so much debugging before. Im very close to a nervous breakdown right now :crazy:

* * *

Process1:

1. I put the \_globals to “0” before entering a if-else loop.

2. I redefine \_globals in if-else loop.

3. I use \_globals new values immediately after the if-else loop is finished (and \_globals are defined/redefined) in a function.

Result:

## All \_globals have value “0”.

* * *

Process 2:

1. I put the \_globals to “0” before entering a if-else loop. (same as before)

2. I redefine \_globals in if-else loop. (same as before)

3. I need to press a button to call the function (same function as before - only difference is that I wait a while).

Result:

## All \_globals use correct values.

Conclusion:

\_globals are not defined properly before code moves on.

Remedy:

Well, with sharedObjects you can use the function “flush” to force the value into the sharedObject immediately.  
If there is a similar function for \_globals that could solve the problem.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 13, 2003, 7:16pm UTC](https://forum.kirupa.com/t/forcing-code-execution-before-moving-on/25430/7 "2003-07-13T19:16:28Z")

</div>

> \*Originally posted by Danneman \*  
> **How could I wait for a \_global to CHANGE its current value?**  
> just put the global vars into another variable and check to see if it’s the same the next time it loops around:

```auto
oldglob = _global; //put this right before you have the global variable change
if (_global != oldglob) {
// do yo thang
} else {
// don't do yo thang
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 16, 2003, 12:15am UTC](https://forum.kirupa.com/t/forcing-code-execution-before-moving-on/25430/8 "2003-07-16T00:15:09Z")

</div>

Well, what happens then is that the code just passes by without executing. If I put it in a while-sentence (while \_global not new value), then the script hangs in an infinite loop.

But I found a workaround to the problem, but since its pretty particular to my code, and is of no real general value, I will not post it.

Thanks for the response, though 🙂
