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

Text => binary

Get Adobe Flash player
by IPFix 22 Dec 2010
    Embed
/**
 * Copyright IPFix ( http://wonderfl.net/user/IPFix )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nZEm
 */

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import com.bit101.components.*;
    
    public class BinaryText extends Sprite {
        
        private  var output:Text;
        private var input:InputText;
        private var radio1:RadioButton;
        private var radio2:RadioButton;
        
        public function BinaryText() {
            output = new Text(this, 20, 70);
            output.setSize( 420,350 );
            input = new InputText(this, 20, 20, 'Do you speek binary ?', onTextChange );
            input.width = 420;
            radio2 = new RadioButton(this,20,45,'With zeros',true, onTextChange);
            radio1 = new RadioButton(this,100,45,'Without zeros', false,onTextChange);
            onTextChange( null );
            
        }
        
        private function stringToBinary(text:String, withZero:Boolean = true):String {
            var s:String = '';
            var c:String;
            for( var i:int= 0; i< text.length; i++ ){
                var charCode:Number = text.charCodeAt(i);
                c = '';
                while( charCode > 0){
                    c += (( charCode & 1 )?'1':'0');
                    charCode >>= 1;
                }
                if( withZero ){ while(c.length<32){c = '0'+c;} }
                s+=c;
            }
            return s;
        }
        
        private function onTextChange(e:Event):void {
            
            output.text =  stringToBinary( input.text , radio2.selected );
        }


    }
}