flash 加载gb2312乱码的处理(2中方法)

1:用binary 加载

 

byteArray 解析

 

var loader:URLLoader  =   new  URLLoader( new  URLRequest( " x.html " ));
loader.dataFormat 
=  URLLoaderDataFormat. BINARY;
loader.addEventListener(Event.COMPLETE, complete);

function complete(event:Event):
void  {
    var BA:ByteArray 
=   new  ByteArray;
    BA.writeBytes((event.target as URLLoader).data);
    BA.position 
=   0 ;
    trace(BA.
readMultiByte (BA.length, " gb2312 " ));
2:用urlStream加载
//使用URLStream取代URLLoader来读取GB数据
private function loadGBTrans():void
{
var request:URLRequest = new URLRequest(gbURL);
var loader:URLStream = new URLStream();
loader.addEventListener(Event.COMPLETE, onloadGBTrans);
loader.load(request);
}
//将读取的内容进行转换后输出,GB的数据被正确显示
private function onloadGBTrans(e:Event):void
{
var stream:URLStream = e.currentTarget as URLStream;
var result:String = stream.readMultiByte(stream.bytesAvailable, "gb2312");
ta.text += "\n转换读取GB数据:\n"+result+"\n";
}

你可能感兴趣的:(html,Flash,idea)