-
cannot seem to read a plain text file
file = date.txt
file contents: date=12/01/2013
code to read the file contents into a variable:
DateFile = new LoadVars();
DateFile.onLoad = function(ok) {
if (ok) {
theDate = DateFile.date;
}
};
DateFile.load("date.txt");
theDate variable is empty
-
.
Hi,
It works for me, maybe try to trace yours out,
PHP Code:
DateFile = new LoadVars();
DateFile.onLoad = function(ok)
{
if (ok)
{
theDate = DateFile.Dated;
//theDate = this.Dated;
// Both the above work
trace(theDate);
myText.text = theDate;
}
else
{
trace("Unable to load file.");
}
};
DateFile.load("date.txt");
swap your txt file to ' Dated=12/01/2013 ' , date might conflict with internal commands/functions!!
-
thanks for the suggestion, changed variable name, still not working, forgot to give my environment, this is a macromedia flash 6.0 actionscript2. I also tried this small change for the target variable, var theDate = DateFile.xdate;
-
Designer, Programmer, Musician
Or maybe the way the variables are placed in the text file? Good luck with this
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
thanks for the reply, I tried renaming the variable, but no luck, I also tried 'var theDate = DateFile.xdate;' to set up the variable.
btw, I'm using action script 2 from macromedia flash mx 6.0 if that makes any difference, but all the manuals and posts indicate to
code as the above example.
-
Designer, Programmer, Musician
Are you writing correctly the variables in the textfile? It must be written this way &theDate = This Date &anotherVariable= Another Value
And so on...
And try this changes in the script:
PHP Code:
DateFile = new LoadVars(); DateFile.load("date.txt"); DateFile.onLoad = function(ok) { if (ok) { DateFile.Dated = this.theDate; trace(this.theDate); myText.text = this.theDate; } else { trace("Unable to load file."); } };
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
.
Hi,
One way is like so.
PHP Code:
DateFile = new LoadVars(); DateFile.onLoad = function(Success) { if (Success) { //theDate = DateFile.Dated; //theName = DateFile.Named; //trace(this.Dated); //trace(this.Named); theDate = this.Dated; theName = this.Named; trace(theDate); trace(theName); // either of the above sets work } else { trace("File not found."); } }; DateFile.load("date.txt");
and text file like so,
Code:
Dated=12/01/2013&
&Named=Saturday&
it's not necessary to use & on the first var, but it makes no difference either way.
Be careful of spaces between the = signs in the txt file too.
Last edited by fruitbeard; 09-19-2013 at 05:55 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|