In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: EUC-JP URIEncode does not work!!

できたっぽい?
Get Adobe Flash player
by mrhdms 11 Sep 2010
// forked from ngs's EUC-JP URIEncode does not work!!
// できたっぽい?
package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.events.Event;
    import flash.utils.ByteArray;
    import flash.events.MouseEvent;
    import flash.system.System;
    [SWF(backgroundColor="#ffffff")]
    public class EUCEncode extends Sprite {
        public function EUCEncode() {
            System.useCodePage = false;
            addEventListener(Event.ADDED_TO_STAGE,init);
        }
        private function init(e:Event=null):void {
            var t:String = "ワンダフル";
            t = encodeEUCURI(t);
            var tf:TextField = new TextField();
            tf.autoSize = "left";
            tf.wordWrap = false;
            tf.text = t;
            tf.y = 50;
            addChild(tf);
        }
        public function encodeEUCURI(str:String):String {
            var b:ByteArray = new ByteArray();
            b.writeMultiByte(str,"euc-jp");
            return escape2(byteArray2Array(b));
        }
        
// ___________________________________________________________   
// http://blog.isocchi.com/2008/08/flexair-actionscripteuc-jpurl.html

        public static function byteArray2Array(byteArray:ByteArray):Array {  
            var array:Array = new Array()  
            byteArray.position = 0;  
            while(byteArray.position <= byteArray.length-1) {  
                array.push(byteArray.readByte() & 0x000000FF);  
            }  
            return array;  
        }
                
        public static function escape2(array:Array):String {  
            var result:String = "";  
      
            for(var i:int=0; i<array.length; i++) {  
                result += "%" + (array[i] as int).toString(16);  
            }  
            return result;  
        } 

// ___________________________________________________________

        
    }
}