Skip to main content
March 26, 2009
Question

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

  • March 26, 2009
  • 2 replies
  • 469 views
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

This is a demo of the script loading the text file
This topic has been closed for replies.

2 replies

Ned Murphy
Legend
March 26, 2009
You're welcome
Ned Murphy
Legend
March 26, 2009
The external traces are being executed before the file is loaded.
March 26, 2009
got it thanks