I’ve made the as3 library to detect charset.1
26/10/2007 00:15
I’ve made the as3 library to detect charset.( Sorry, This version is for Japanese only!)
This library is here:
http://www.hi-farm.net/aslib/detect.lzh
This library is to detect charset.
We can encode charset to “utf-8″ by using readMultiByte method in flash.net.URLStream if we set charset that loaded by application, but we can’t detect charset.
I made ths library to solve this kind of trying problem.
— How to use —
detecting the files on web: DetectOnWeb class
detecting the files on your system(i.e. AIR) : DetectOnAir class
Another way of saying,
By using URLStream class : DetectOnWeb class
By using FileStream class : DetectOnAir class
flow of using this library is below:
1 import this class.
2 create an instance.
3 create listener object.
4 use detectCharset( url:String ) method.
5 get data
This is the sample:
DetectOnAir class
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:WindowedApplication xmlns:mx=”http://www.adobe.com/2006/mxml\”
;; layout=”absolute” creationComplete=”initApp()”>
<mx:Script>
<![CDATA[
import net.hifarm.encode.DetectOnAir;
private var detect:DetectOnAir;
private function initApp():void{
detect = new DetectOnAir();
detect.addEventListener("completeData", comp);
//
detect.detectCharset("file:///Users/mmlemon/Documents/Flex%20Builder%20Moxie/indexInPDF/shift-jis.txt";;);
}
private function comp(e:Event):void{
trace(detect.result);
}
]]>
</mx:Script>
</mx:WindowedApplication>
DetectOnWeb
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml\”
;; layout=”absolute” creationComplete=”initApp()”>
<mx:Script>
<![CDATA[
import net.hifarm.encode.DetectOnWeb;
private var detect:DetectOnWeb;
private function initApp():void{
detect = new DetectOnWeb();
detect.addEventListener("completeData", comp);
detect.detectCharset("http://blog.hi-farm.net/"
;;);
}
private function comp(e:Event):void{
trace(detect.result);
}
]]>
</mx:Script>
</mx:Application>
We can get charset “detect.result”.
For example, “iso-2022-jp” , “euc-jp” , “utf-8″ , “shift-jis” , “iso-8859-2″, and so on.
Of course, if application throws error, you can get error message from detect.result.
Caution:
Now you can detect charset ONLY Japanese by using my library.
I’m glad to report any bugs and request.