手机
当前位置:查字典教程网 >网页设计 >Flash教程 >Flash AS解决中文mp3乱码
Flash AS解决中文mp3乱码
摘要:Flash如果MP3的ID3标签使用GB2312编码,那么在Flash脚本输出时是乱码的代码1vars:Sound=newSound(thi...

Flash如果MP3的ID3标签使用GB2312编码,那么在Flash脚本输出时是乱码的

代码1

var s:Sound=new Sound(this);

s.loadSound("dxh.mp3",false);

s.onID3=function(){

trace(this.id3.songname);

}

输出结果是:

?&IExcl;???

dxh.mp3的ID3v1的标签正确应该是songname="丁香花",看来FLASH在转码上出现了问题。我们来看看songname这个字符串中倒底是什么?

代码2:

var s:Sound=new Sound(this);

s.loadSound("dxh.mp3",false);

s.onID3=function(){

var songname:String=this.id3.songname;

for(var i=0;i<songname.length;i ){

trace(songname.charCodeAt(i));

}

}

输出结果是:

182

161

207

227

187

168

我们使用计算器转换成16进制就是"B6 A1 CF E3 BB A8";

正好是"丁香花"的GB2312编码,我们还是用FLASH来试试

System.useCodepage=true;

trace(unescape("丁香花"));

输出结果是:

丁香花

那么为什么代码1出现乱码现象,是因为FLASH将GB2312当作了UTF-8来解释,我们再来测试一下:

代码3:

var s:Sound=new Sound(this);

s.loadSound("dxh.mp3",false);

s.onID3=function(){

var songname:String=this.id3.songname;

trace(escape(songname));

}

结果是:

?????¨

问题的原因我们找到了,只要将GB2312转换成UTF-8编码就能显示正常了,可是如果转换呢,大家注意看代码2,我再测试一下想法

代码4:

System.useCodepage=true;

var gb:String=unescape("丁香花");

System.useCodepage=false;

trace(gb);

trace(escape(gb));

输出结果:

丁香花

涓侀鑺

【Flash AS解决中文mp3乱码】相关文章:

Flash背景设定技巧两则

Flash as3教程:OutDisplay类

Flash制作荧光文字特效

Flash绘制小龙与花插画场景

Flash cs3无法导出swf文件解决方法

flash中嵌入字体实现原理及代码

Flash AS 实例进阶 导航条实现方法

彻底消灭Flash动画中的乱码

Flash as3嵌入中文字体的方法

Flash文件增大原因与解决方法

精品推荐
分类导航