Skip to main content
Craig Grummitt
Inspiring
April 12, 2010
Question

FileStream writing strange characters

  • April 12, 2010
  • 1 reply
  • 3505 views

I'm trying to write out some Spanish text using FileStream(AIR), but special Spanish characters are writing out strange.

Here's a stripped down basic version of the problem, for you to try at home...

import flash.filesystem.*;
import flash.net.FileFilter;

import flash.events.Event;

var fileToSave:File = new File();
fileToSave.browseForSave("Save");

fileToSave.addEventListener(Event.SELECT, fileSaveSelected);


function fileSaveSelected(event:Event):void {
     var stream:FileStream = new FileStream();
     stream.open(event.target as File, FileMode.WRITE);
     stream.writeUTFBytes("crepúscolo");
     stream.close();
}

This should write out the word "crepúscolo", instead it writes out "crepúscolo"...

I've tried other combinations, for example i've tried stream.writeMultiByte with a variety of charsets, sometimes giving different results, but never the desired result...

Ideas anyone?

This topic has been closed for replies.

1 reply

Inspiring
April 13, 2010

You can't use ascii characters directly in flash. Use String.fromCharCode(250) for ú

stream.writeUTFBytes("crep" + String.fromCharCode(250) + "scolo");

Craig Grummitt
Inspiring
April 13, 2010

Nope, that wasn't it. Still outputs crepúscolo.

I believe the string is treated the same by Flash whether its set directly, or indirectly using String.fromCharCode.

For example:

trace("crepúscolo");

outputs:

crepúscolo

Other ideas, anyone?

Inspiring
April 13, 2010

Does it change if use alter System.useCodePage?

Funny, your char is getting split into 2 bytes. Check this out:

var u:int = 250; // code of ú: fa
var a:int = 195; // code of Ã: c3
var d:int = 186; // code of º: ba
trace(u.toString(16), a.toString(16), d.toString(16));
trace(encodeURI("ú")); // %C3%BA

FYI, your code works as expected on my system (WinXP, US English)...

Message was edited by: tedalde2  Added works on my system.