 
         protected function saveAsUtf8(str:String):ByteArray {
             var bytes:ByteArray = new ByteArray();
+            // add BOM
+            bytes.writeByte(0xEF);
+            bytes.writeByte(0xBB);
+            bytes.writeByte(0xBF);
+
             bytes.writeUTFBytes(str);
 
             return bytes;

        protected function register():void {
        	ExternalInterface.addCallback('setFileName', setFileName);
        	ExternalInterface.addCallback('setCharset', setCharset);
        	ExternalInterface.addCallback('setStrData', setData);
        }

        // set file name


        protected function saveAsUtf16(str:String):ByteArray {
            var bytes:ByteArray = new ByteArray();
            bytes.writeByte(0xFF);
            bytes.writeByte(0xFE);
            for (var i:int = 0; i < str.length; i++) {
                var code:int = str.charCodeAt(i);
                if (code < 0XFF) {
