# Variables

**URL:** <https://forum.kirupa.com/t/variables/7523>\
**Category:** Uncategorized\
**Created:** [November 2, 2002, 3:30am UTC](https://forum.kirupa.com/t/variables/7523 "2002-11-02T03:30:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![TimberBoon](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@TimberBoon](https://forum.kirupa.com/u/TimberBoon)\
**Post date:** [November 2, 2002, 3:30am UTC](https://forum.kirupa.com/t/variables/7523/1 "2002-11-02T03:30:31Z")

</div>

If I load a variable from a text file into \_root. How do I access it in actionscript for something like an if statement? I tried putting just the variable and \_root.variable but neither worked. Also any dynamic text boxes I have correctly display the variable. It must be possible to use these external values for stuff other than text boxes right? The basic idea is to use these values in an if statement that will decide whether it should be in frame 1, 2 or 3.  
Any help is appreciated.

---

<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:** [November 2, 2002, 4:41am UTC](https://forum.kirupa.com/t/variables/7523/2 "2002-11-02T04:41:17Z")

</div>

u should load ur variable into level0 if u want to use it for \_root, the external variable should work anyway!

yours,

h88

---

<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:** [November 2, 2002, 5:26am UTC](https://forum.kirupa.com/t/variables/7523/3 "2002-11-02T05:26:17Z")

</div>

remember too that the variable will take time to load. It’s a good practice to create a preloader which looks for a particular variable from the txt file, like “flag=true” for instance. Located at the end of the txt doc, you just make sure to wait until flag=true in the Flash production before attempting to read the other variables in the txt file.

---

<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:** [November 3, 2002, 4:08am UTC](https://forum.kirupa.com/t/variables/7523/4 "2002-11-03T04:08:29Z")

</div>

Alright I’m currently loading the variables into level0. When I test the movie and list the variables it tell me the 12 or so variables and the correct value they are equal to. But when I attempt to use them in an if statement it’s like it doesnt exist. I’ve tried all kinds of variations on the if statement.

if (outcome=win)  
if (\_root.outcome=win)  
if (level0.outcome=win)  
if (\_level0.outcome=win)

and each of those with “win” in quotes.

When I list the variables when testing them they are given as \_level0.variable = "whatever  
".

And this is how the loading of the variables is written:

loadVariablesNum (“admin/match.txt”, 0);

I’m not a completely newbie at a/s but there are likely dozens of little tricks I don’t know. So chances are it’s something pretty simple…

---

<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:** [November 4, 2002, 6:18am UTC](https://forum.kirupa.com/t/variables/7523/5 "2002-11-04T06:18:15Z")

</div>

easy mistake considering the nature of a/s is a little different than some of the more popular programing tools. I’ve seen this mistake a hundred times from newbies, including myself when I first started out. (ok I admit it… 95 of the 100 times were me. )

if (outcome=win)  
if (\_root.outcome=win)  
if (level0.outcome=win)  
if (\_level0.outcome=win)

should be

if (outcome==win)  
if (\_root.outcome==win)  
if (level0.outcome==win)  
if (\_level0.outcome==win)

if you use a single equals sign, Flash thinks that you are telling it to assign the strings to those variables, in A/S it is a double equals symbol which means “compare these objects”.

---

<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:** [November 5, 2002, 12:19am UTC](https://forum.kirupa.com/t/variables/7523/6 "2002-11-05T00:19:48Z")

</div>

Omg!! I knew that too! I remember typing those double equal signs out before. lol. Guess that’s what happens when you go and decide to learn flash and end up taking a break from it… :  
Thanks for the reminder 😃

---

<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:** [December 5, 2002, 5:38am UTC](https://forum.kirupa.com/t/variables/7523/7 "2002-12-05T05:38:56Z")

</div>

Alright no matter what I do flash doesn’t recongize that the variable exists when accessing it in a/s. It will display it in text boxes and it will list it in the output when you debug and list the variables.

debug ex:

Variable \_level1.status = “Defending”

Now if I place a textbox and give it that variable name it will display “Defending”. But if I trace the variable or try to use it in a/s it is returned as undefined.

So either I need a real good explanation of why it isn’t working or maybe someone could make a real quick .fla demonstrating the loaded variable being used in some a/s. Thx again.

---

<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:** [January 26, 2003, 1:11am UTC](https://forum.kirupa.com/t/variables/7523/8 "2003-01-26T01:11:09Z")

</div>

Was anyone able to figure this problem out? I’m having the same problem as Timeberboom and decided to search the forum before posting on it, but this thread looks unanswered.

Here is a recap of the basic problem:

It seems that when the loadVariablesNum() command is used to read in variables from a textfile, the values of those variables can be displayed in dynamic textboxes, but you can’t operate on them with good ole’ fashioned ActionScript.

Here is a concrete example for anyone interested in solving the problem or explaining the answer:

1. First, create a text file and place a variable or two inside using the MIME format: x=12&y=23

For the purposes of this post, let’s call the file data.txt

1. Open a new Flash document in the same directory and, on the stage, create a dynamic textfield and assign its variable property to x.

2. On the main timeline, type the following a/s code:

loadVariablesNum(“data.txt”,0);  
trace("x = " + x);

1. Save the file and run it. You should see the value 12 appear in the textbox (good news). However, the value 12 will not appear with the trace command (bad news). Specificying \_root.x doesn’t seem to help either. It is as if the program does not recognize the variable.

Does anyone know the solution to this problem? I assume it is something simple, but, sigh, I’m not sure. Any help would be appreciated.

---

<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:** [January 30, 2003, 1:09am UTC](https://forum.kirupa.com/t/variables/7523/9 "2003-01-30T01:09:33Z")

</div>

I was surprised this thread rose from the dead. 🙂 Anyway I didn’t post any reply that I fixed it because I assumed the thread would never return so here ya go. As stated above (I think. I’m doing this from memory) you have do a check that the last variable in the data.txt file is loaded. So after you load the txt file with:

loadVariablesNum(“data.txt”,0);

In the next frame make an if statement to check it.

if (y==23) {goto this and that and make some a/s that uses the vars}  
else {goto the next frame which in turn returns you to this one for the test again}

Which makes me wonder, can you just point a piece of a/s to goto the same frame it’s in and execute the script from the beginning again?

Also I made a little timer that counts to some number (I think I gave it around 15-20 sec) and if the data isn’t loaded yet because it timed out it will restart the loading process by returning to frame 1, reseting the timer and loading data.txt again.

Hope this helped I really cut some corners in what I wrote above. If anything is unclear feel free to reply. 🙂
