FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Reading from text file into Flash





biljap
Hi!

I have a problem reading values from text file into Flash.

I have an array:
Code:
var s:Array = new Array(10);


and I need to lead values from the file into it. I use the following code:

Code:
var myData = new LoadVars();
myData.onLoad = function(succes){
        if(succes){
   _root.s[0] = this.s1;
         // …
        _root.s[9] = this.s10;
        } else trace("Error loading data")
}


When I try trace inside onLoad function I can see that data has been loaded but when I try to access to the values of array s after

Code:
myData.load("test.txt");


I get “Undefined”.

Can somebody please tell me what is wrong with my code? Why I can’t read values into array?
darth_revan
if you are using 8th version, you'll see that when you type that code:
Code:

myData.onLoad(

you see the declaration of the function. For example, you see myData.onLoad(success). Notice that, it's not succes, its success. First i thought it was a variable that you've created earlier, but i see that it's just a spelling mistake.
Code:

var myData = new LoadVars();
myData.onLoad = function(success){
        if(success){
   _root.s[0] = this.s1;
         // �
        _root.s[9] = this.s10;
        } else trace("Error loading data")
}

this is the correct code, i suppose.
m-productions
actully his code is correct, the problem is that you are not giveing flash enough time to Load the vars, you must make it wait a few seconds so that it can load the text.... also, i like useing this instead of load

Code:

var myData = new LoadVars();
var sendData = new LoadVars();
sendData.cachekiller = random(9999);
// this makes it so it will not load your text from the computers cache, incase you change it.
sendData.sendAndLoad("your site", myData, POST);
myData.onLoad = function(success){
        if(success){
   _root.s[0] = this.s1;
         // �
        _root.s[9] = this.s10;
        } else trace("Error loading data")
}


that works a lot better.
Related topics
users online, using php and text file
Hints? or reading to far into it?
styling text string read from plain text file
Integrating Mp3s Into Flash?
Visual basic 6.0 help me with saving code please
Help importing CSV file into MySQL database
Deleting certain lines from text file
HELP, reading text file from USB drive in visual basic
download a text-file daily
how to add a text file in mp3 data using java ?
English Dictionary in text file or sql database
Perl how to encrypt your text file contents with Perl
edit option not available for a text file
want to delete first 5 lines in a text file
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.