Language: ChineseGermanSpanishFrenchDutchItalianRussian
123 Flash Chat Forums

Go Back   TOPCMM Community > SWFKit > SWFKit Pre-sales

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-07-2004, 07:25 PM
Junior Member
 
Join Date: May 2004
Posts: 4
Default file stream

I am very interested in buying swfkit. However, I have been reviewing the trial version and I have had trouble getting the readfromfile function to work. I want to be able to read a text file that just contains several lines of text. I can't seem to get it to work. Could you please send me a sample?

Thanks
Reply With Quote
  #2 (permalink)  
Old 05-08-2004, 02:19 PM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re:file stream

Code:
var f = new FileStream('c:\\test.txt');
if (f != null)
{
    while (f.pos < f.length)
    {
        trace(f.readLine());
    }
}
If you want to read the entire text file by one call, do like this
Code:
var f = new FileStream('c:\\test.txt');
if (f != null)
{
    trace(f.readString());
}
Reply With Quote
  #3 (permalink)  
Old 05-10-2004, 03:50 PM
Junior Member
 
Join Date: May 2004
Posts: 4
Default Re:file stream

Thanks for the code. However, I wanted to try to save the data from the file to a variable in Flash. Here is the code I tried but it did not work. Thanks for the assistance.

var f = new FileStream('c:\\test.txt');
var g = "";
if (f != null)
{
trace(f.readString());
g = f.readString();
}
FlashPlayer.setVariable("_level0.str_loc", g.toString());
Reply With Quote
  #4 (permalink)  
Old 05-11-2004, 12:24 AM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re:file stream

Please don't call the "readString()" method twice. The first call will return the proper result. But the file pointer seeks to the end of the text file after the first call returns. Then the second call returns a empty string.

Please do like this
Code:
var f = new FileStream('c:\\test.txt');
var g = "";
if (f != null)
{
    g = f.readString();
    trace(g);
}
FlashPlayer.setVariable("_level0.str_loc", g.toString());
Or
Code:
var f = new FileStream('c:\\test.txt');
var g = "";
if (f != null)
{
    trace(f.readString());
    f.pos = 0;
    g = f.readString();
}
FlashPlayer.setVariable("_level0.str_loc", g.toString());
Reply With Quote
Reply

Was this information helpful?    Yes No



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:37 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.