Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

load a variable into memory from a text file

Status
Not open for further replies.

AP81

Programmer
Apr 11, 2003
740
AU
I am trying to load a variable into memory from a text file. I can read the data into a textbox, however I cannot read it into a variable. Here is my code below:


This loads into a textbox okay:
Code:
ConfigData = new LoadVars();
ConfigData.onLoad = function(){
    

   myText_txt.text = this.eventYear + "\n" +
                     this.eventMonth + "\n" +
             this.eventDay + "\n" +
                     this.eventHour + "\n" +
                     this.eventMin + "\n" +
                     this.eventSec + "\n" +
                     this.Ms;
};
ConfigData.load("DateConfig.txt");

Now, these variables always turn out to be undefined if you run a trace on them:
Code:
ConfigData = new LoadVars();
ConfigData.onLoad = function(){
    
   _global.eventYear = this.eventYear;
   _global.eventMonth = this.eventMonth;
   _global.eventDay = this.eventDay;
   _global.eventHour = this.eventHour;
   _global.eventMin = this.eventMin;
   _global.eventSec = this.eventSec;
   _global.eventMs = this.eventMs;
};
ConfigData.load("DateConfig.txt");

My application is very simple: it has two layers and one frame for each layer. The above code is on its own layer. The other layer has some action script that needs the variables above to perform a calculation.

Any help is appreciated.
Thanks in Advance.




------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
Sorry I only got clumsy version using the older "loadVariables":

1. create a dummy movie on a dummy layer. (To be the target to load your External File. Also to be the event listener of the loading operation). Name this movie "dummy1".

2. Add below MOVIE-CLIP-LEVEL Action to "dummy1".

onClipEvent(data) {
/:eventYear=eventYear;
/:eventMonth=eventMonth;
...
gotoAndPlay("_root:init");
}

3. On Scene1, first frame-level Action, put:

loadVariables("/DateConfig.txt", dummy1);

4. I was able to read desired variables at frames subsequent to the "init" frame.

(above basically come from Flash MX help searching "loadVariables". Maybe you can gear this more OO)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top