Language: ChineseGermanSpanishFrenchDutchItalianRussian
123 Flash Chat Forums

Go Back   TOPCMM Community > SWFKit > SWFKit Support

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-27-2007, 08:44 PM
Junior Member
 
Join Date: Jun 2007
Posts: 6
Default saving data to file

Hi

I am loading variables in my application using LoadVars in Actionscript from simple html file.
And I need to save these variables back to this html file after changing. Is there any posibility to do this via SWFkit and how can I do this?

Thanks in advance!
Reply With Quote
  #2 (permalink)  
Old 06-28-2007, 01:38 AM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re:saving data to file

Do you mean saving the variables to a local disk file or sending them back to the remote html file? If former, you can use the FileStream or DataFile object in swfkit; if latter, you can use the "LoadVars" object in actionscript.
Reply With Quote
  #3 (permalink)  
Old 07-08-2007, 10:42 AM
Junior Member
 
Join Date: Jun 2007
Posts: 6
Default Re:saving data to file

I mean saving data to a local disk file. So I tried to use FileStream object:
Code:
stream = new FileStream("data.html", "w+" );
stream.writeLine("&header1="+_root.data_lv.header);
....
stream.close();
It looks like everything works fine. BUT I faced another problem: This method saves data in "Windows" encoding and LoadVars object reads variables in UTF-8 encoding... So my program can not read them after saving...

Is there any posibility to change encoding of FileStream???
Reply With Quote
  #4 (permalink)  
Old 07-09-2007, 09:14 AM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default Re:saving data to file

The following code shows how to use the "toUTF8" method (ffish script method) to write a XML file

Code:
//convert a string to an utf8 encoded string stream
function toUTF8(string)
{
var i;
var stream = new StringStream;

for (i = 0; i < string.length; i++)
{
var code = string.charCodeAt(i);

if (code < (1 << 7))
{
stream.put(code);
}
else if (code < (1 << 11))
{
stream.put((code >> 6) | 0xC0);
stream.put((code & 0x3F) | 0x80);
}
else if (code < (1 << 16))
{
stream.put(0xE0 | ((code >> 12) & 0x0F));
stream.put(0x80 | ((code >> 6) & 0x3F));
stream.put(0x80 | (code & 0x3F));
}
else if (code < (1 << 21))
{
stream.put((code >> 18) | 0xe0);
stream.put(((code >> 12) & 0x3f) | 0x80);
stream.put(((code >> 6) & 0x3f) | 0x80);
stream.put((code & 0x3f) | 0x80);
}
}

return stream;
}

var str = '<project name="test" default="init" basedir=".">' +
'     <target name="init">' +
'          <!-- displays Hello in Chinese -->' +
'          <echo message="The Chinese word is: ÊÀ¼Í"/>' +
'     </target>' +
'</project>';

var f = new FileStream("c:\\1.xml", "w");
f.writeLine('<?xml version="1.0" encoding="UTF-8"?>');
f.write(toUTF8(str));
f.close();
Reply With Quote
  #5 (permalink)  
Old 07-09-2007, 11:25 AM
Junior Member
 
Join Date: Jun 2007
Posts: 6
Default Re:saving data to file

Thank's a lot!!!
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 04:22 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.