# Reading data from a text file but can't use the data outside of the function

**URL:** <https://forum.kirupa.com/t/reading-data-from-a-text-file-but-cant-use-the-data-outside-of-the-function/285020>\
**Category:** Uncategorized\
**Created:** [March 26, 2009, 7:32am UTC](https://forum.kirupa.com/t/reading-data-from-a-text-file-but-cant-use-the-data-outside-of-the-function/285020 "2009-03-26T07:32:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mauprice](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@mauprice](https://forum.kirupa.com/u/mauprice)\
**Post date:** [March 26, 2009, 7:32am UTC](https://forum.kirupa.com/t/reading-data-from-a-text-file-but-cant-use-the-data-outside-of-the-function/285020/1 "2009-03-26T07:32:38Z")

</div>

I am trying to load a variable from data in a text file.

I can read the text file fine but the variable data seems only to be available with in the function that reads it.

I need to use the variable data outside of the function.

Does anyone have any suggestions to work around this issue?

**This is the actionscript code i’m using.**

var pathVars= new LoadVars();  
pathVars.onLoad=function(ok) {  
if(ok)  
{  
trace(“Loading”);  
path\_var=pathVars.path;  
trace("This is within the function "+path\_var);  
pathVar0="This is within the function… "+path\_var;

```
          Yet the path_var is available here fine.
}

```

};  
pathVars.load(“mypath.txt”);

This is where the path\_var becomes undefined  
trace("This is outside the function… "+path\_var);  
pathVar1="This is outside the function… "+path\_var;

[This is a download link for the FLA zip file](http://www.interactivewebconcepts.com/text_path/mypath.zip)

[This is a demo of the script loading the text file](http://www.interactivewebconcepts.com/text_path/index.html)
