# FMX-variable accessible outside of functions

**URL:** <https://forum.kirupa.com/t/fmx-variable-accessible-outside-of-functions/27828>\
**Category:** flash\
**Created:** [August 7, 2003, 12:30am UTC](https://forum.kirupa.com/t/fmx-variable-accessible-outside-of-functions/27828 "2003-08-07T00:30:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![borispc](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@borispc](https://forum.kirupa.com/u/borispc)\
**Post date:** [August 7, 2003, 12:30am UTC](https://forum.kirupa.com/t/fmx-variable-accessible-outside-of-functions/27828/1 "2003-08-07T00:30:51Z")

</div>

Hi! :hat:

I don’t know why the value of my variable my\_str is undefined outside of this function:

loadText = new loadVars();  
loadText.load(“data.txt”);  
loadText.onLoad = function(success) {  
if (success) {  
my\_str = this.name;  
trace(my\_str)//my\_str has the right value  
} else {  
trace(“Error loading data”);  
}  
}

trace(my\_str)//my\_str is undefined

ps: I tried making my\_str a global function or even defining it as \_root.my\_str but I always get the same result…it’s undefined outside the function…I need that value for something else so…  
anyone has a clue???

---

<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:** [August 7, 2003, 12:45am UTC](https://forum.kirupa.com/t/fmx-variable-accessible-outside-of-functions/27828/2 "2003-08-07T00:45:39Z")

</div>

the reason for an onLoad function is that it allows you a place to put code _waiting_ for your content to load. Why you need to wait is because loaded values from a text file arent loaded right away. Because they arent loaded right away, any code run in that frame not in the onLoad function will have no access to what was loaded because it was run all at once - all at that time that it was told to load in the first place. Because of that your trace(my\_str) on the timeline will get run before the onLoad is called meaning it will have no value to find.
