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

Convert String Text to Binary N Base

Get Adobe Flash player
by WLAD 04 Jan 2016
    Embed
/**
 * Copyright WLAD ( http://wonderfl.net/user/WLAD )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/UJlg
 */

// forked from WLAD's FF: WFLPortalbe minifyed 1.1
// forked from WLAD's WFLPortalbe minifyed 
package {
    import flash.display.Sprite;
	[SWF(width = "465", height = "465" )]
	public class WFLPortable extends Sprite
	{
		public function WFLPortable() 
		{
			WG.INIT( stage );
			
			Comp.mobileSlideMenu = false;
			Comp.Margin = 5;
			Comp.Gap = 5;
			Comp.Scale = 2;
			
			var C:Comp = new Comp( this );
			var M:String = "Dec";
			var T:String = "";
			
			var F:Function = function():void {
				
				var O:String = "";
				
				var TXT:String = "";
				var BASE:int;
				var LEN:int;
				if ( M == "Dec" ) { BASE = 10; LEN = 3 } 
				else if ( M == "Hex" ) { BASE = 16; LEN = 2; }
				else if ( M == "Oct" ) { BASE = 8; LEN = 4; } 
				else if ( M == "Bin" ) { BASE = 2; LEN = 8; }
				
				var LINE:int = 0;
				
				for ( var i:int = 0; i < T.length; i++ )
				{
					TXT = T.charCodeAt(i).toString( BASE ).toUpperCase();
					
					while ( TXT.length < LEN ) TXT = "0" + TXT;
					
					TXT += " ";
					
					if ( ++LINE >= BASE ) 
					{
						O += TXT + "\n";
						LINE = 0;
					}
					else O += TXT;
				}
				
				output.text = O;
			};
			
			C.addLabel( "Input" );
			C.addInput( "", function( text:String ):void {
				
				T = text;
				F();
				
			});
			
			C.addLabel("Method");
			C.addSwitch( function( method:String ):void
			{
				M = method;
				F();
				
			}, "Dec", "Hex", "Bin", "Oct" );
			
			C.addLabel("Output");
			var output:* = C.addOutput( 123 );
		}
	}
}


// 1.1 : Minified single line WFLPortalbe ( http://wonderfl.net/c/efy55 )
import flash.text.*;import flash.display.*;import flash.events.*;import flash.geom.*;import com.bit101.components.*;class WG{static public var W2:int;static public var H2:int;static public var W:int;static public var H:int;static private var canvas:Shape;public static function INIT(stage:Stage, bgColor:uint=0x000000, frameRate:int=60, preventScale:Boolean=true):void{canvas=new Shape();stage.addChildAt(canvas, 0);var onStageResize:Function=function(any:*=null):void{W=stage.stageWidth;W2=W>>1;H=stage.stageHeight;H2=H>>1;canvas.graphics.clear();canvas.graphics.beginFill(bgColor);canvas.graphics.drawRect(0,0,W,H);canvas.graphics.endFill();exe(onResize);};stage.addEventListener('resize', onStageResize);stage.addEventListener('rightMouseDown', function(e:*):void{exe(onRightMouseDown);});stage.addEventListener('rightMouseUp', function(e:*):void{exe(onRightMouseUp);});stage.addEventListener('mouseDown', function(e:*):void{exe(onMouseDown);});stage.addEventListener('mouseUp', function(e:*):void{exe(onMouseUp);});stage.addEventListener('enterFrame', function(e:*):void{exe(onFrame);});if(preventScale){stage.align='tl';stage.scaleMode='noScale';}stage.frameRate=frameRate;exe(onInit);onStageResize();}static private function exe(m:Function):void{if(m !=null)m();}static public var onMouseDown:Function=null;static public var onMouseUp:Function=null;static public var onRightMouseDown:Function=null;static public var onRightMouseUp:Function=null;static public var onFrame:Function=null;static public var onResize:Function=null;static public var onInit:Function=null;}class Canvas{public var limitMinX:Number=0;public var limitMinY:Number=0;public var limitMaxX:Number=500;public var limitMaxY:Number=500;protected function limitMinMax(val:Number, x:Boolean):Number{if(x)return val<limitMinX?limitMinX :(val>limitMaxX?limitMaxX : val);return val<limitMinY?limitMinY :(val>limitMaxY?limitMaxY : val);}public function Canvas(target:DisplayObjectContainer){this.target=target;canvas=new Shape();target.addChild(canvas);}public function get display():Shape{return canvas;}private var target:DisplayObjectContainer;private var canvas:Shape;public function Clear():void{canvas.graphics.clear();}public function DrawRect(color:uint, x:Number, y:Number, w:Number, h:Number):void{canvas.graphics.lineStyle();canvas.graphics.beginFill(color);canvas.graphics.drawRect(x, y, w, h);canvas.graphics.endFill();}public function DrawsRectangle(color:uint, area:Rectangle):void{canvas.graphics.lineStyle();canvas.graphics.beginFill(color);canvas.graphics.drawRect(area.x, area.y, area.width, area.height);canvas.graphics.endFill();}public function DrawCircle(color:uint, radius:Number, x:Number, y:Number):void{canvas.graphics.lineStyle();canvas.graphics.beginFill(color);canvas.graphics.drawCircle(x, y, radius);canvas.graphics.endFill();}public function DrawPoint(color:uint, point:Point):void{DrawCircle(color, 4, point.x, point.y);}public function DrawText(text:String, x:Number, y:Number, origin:Boolean=false, color:uint=0x808080, size:int=16, background:int=-1, font:String="_sans", bold:Boolean=false):void{var tf:TextField=new TextField();tf.autoSize='left';tf.defaultTextFormat=new TextFormat(font, size, color, bold);tf.text=text;if(background !=-1){tf.background=true;tf.backgroundColor=background;}target.addChild(tf);var b:Rectangle=tf.getBounds(target);var bd:BitmapData=new BitmapData(b.width, b.height, true, 0x00000000);bd.draw(tf);target.removeChild(tf);tf=null;canvas.graphics.lineStyle();var tx:Number=x-(origin?b.width/2 : 0);var ty:Number=y-(origin?b.height/2 : 0);canvas.graphics.beginBitmapFill(bd, new Matrix(1,0,0,1,tx,ty), false);canvas.graphics.drawRect(tx, ty, b.width, b.height);canvas.graphics.endFill();}}class DragBox extends Sprite { private var size:Number;private var min:Number;private var max:Number;private var onDrag:Function=null;private var color:uint=0x0;private var limitColor:uint=0xFF0000;private var oriantationHorizontal:Boolean;public function DragBox(size:Number=20, color:uint=0xFF8000, min:Number=NaN, max:Number=NaN, oriantationHorizontal:Boolean=true, onDrag:Function=null){this.size=size;this.oriantationHorizontal=oriantationHorizontal;this.color=color;this.min=min;this.max=max;this.onDrag=onDrag;if(oriantationHorizontal)rotation=-90;if(!isNaN(min))oriantationHorizontal?x=min : y=min;scaleX=scaleY=1.4;draw(0);useHandCursor=buttonMode=true;addEventListener("addedToStage", function(e:*=null):void{addEventListener("mouseDown", function(e:*=null):void{addEventListener("enterFrame", drag);});stage.addEventListener("mouseUp", function(e:*=null):void{scaleX=scaleY=1;removeEventListener("enterFrame", drag);});});}public function get travelArea():Rectangle{if(isNaN(min)||isNaN(max))return null;var rect:Rectangle=new Rectangle(this.x-size/2, this.y-size/2, size+max-min, size+max-min);if(oriantationHorizontal){rect.height=size;rect.x=min-size/2;}else{rect.width=size;rect.y=min-size/2;}return rect;}public function get value():Number{if(isNaN(min)||isNaN(max))return 0;var N:Number=oriantationHorizontal?x : y;return(N-min)/(max-min);}public function set value(V:Number):void{if(isNaN(min)||isNaN(max))return;var N:Number=V*(max-min)+min;oriantationHorizontal?x=N : y=N;if(V==0)draw(1);else if(V==1)draw(-1);else draw(0);}public function draw(limit:int):void{graphics.beginFill(limit==0?color : limitColor);graphics.drawRoundRect(-size/2,-size/2, size, size, size*(7/20));graphics.endFill();graphics.beginFill(0xFFFFFF);if(limit<0){graphics.moveTo(0,-size/4);graphics.lineTo(size/4, size/10);graphics.lineTo(-size/4, size/10);graphics.lineTo(0,-size/4);}else if(limit>0){graphics.moveTo(0, size/4);graphics.lineTo(size/4,-size/10);graphics.lineTo(-size/4,-size/10);graphics.lineTo(0, size/4);}else graphics.drawCircle(0, 0, size/4);graphics.endFill();}private function drag(e:*=null):void{scaleX=scaleY=1.4;var N:Number=oriantationHorizontal?parent.mouseX : parent.mouseY;if(!isNaN(min)&&N<min){N=min;scaleX=scaleY=1;draw(1);}else if(!isNaN(max)&&N>max){N=max;scaleX=scaleY=1;draw(-1);}else draw(0);oriantationHorizontal?x=N : y=N;if(onDrag !=null)onDrag();}}class Comp{static public var Scale:Number=2;static public var mobileSlideMenu:Boolean=true;static public var Margin:int=10;static public var Gap:int=8;public function addLabel(text:String):void{fitComponents(new Label(cont, 0, 0, text.toUpperCase()));}public function addCheckBox(label:String, value:Boolean, onChange:Function):void{var c:CheckBox=new CheckBox(cont, 0, 0, label.toUpperCase(), function(any:*=null):void {onChange(c.selected);});fitComponents(c);}public function addButton(label:String, onPush:Function):void{fitComponents(new PushButton(cont, 0, 0, label.toUpperCase(), function(any:*=null):void {onPush();}));}public function addInput(label:String="", onInput:Function=null):InputText{var t:InputText=new InputText(cont, 0, 0, label.toUpperCase(), function(any:*=null):void{if(onInput !=null)onInput(t.text);});fitComponents(t);return t;}public function addSlider(label:String, value:Number, min:Number, max:Number, tick:Number, labelPrecision:int, onChange:Function):void{var s:HUISlider=new HUISlider(cont, 0, 0, label.toUpperCase(), function(any:*=null):void{onChange(s.value);});s.minimum=min;s.maximum=max;s.value=value;s.labelPrecision=labelPrecision;s.tick=tick;fitComponents(s);}public function addOutput(h:Number=50):TextArea{var t:TextArea=new TextArea(cont, 0, 0,"");t.editable=false;t.height=h;t.draw();t.textField.defaultTextFormat=new TextFormat("Arial", 8, 0x0, null, null, null, null, null,"left", 0, 0, 0, 0);t.text="";t.textField.embedFonts=false;fitComponents(t);return t;}public function addSwitch(onChange:Function, ...StringArguments):void{var hbox:HBox=new HBox(cont, 0, 0);var bw:Number=(w-(Margin*2)-2*Scale)/StringArguments.length/Scale;hbox.spacing=0;for(var i:int=0;i<StringArguments.length;i++){var b:PushButton=new PushButton(hbox, 0, 0, String(StringArguments[i]), function(target:*):void{for(var j:int=0;j<StringArguments.length;j++)PushButton(hbox.getChildAt(j)).selected=false;PushButton(target.target).selected=true;onChange(PushButton(target.target).label);});b.toggle=true;b.selected=i==0;b.width=bw;b.x=bw*i;hbox.addChild(b);}fitComponents(hbox);}private var dragBox:DragBox;private var list:Vector.<Component>;private var parent:Sprite;private var cont:Sprite;private var w:int=465;private var h:int=465;public function Comp(parent:Sprite, w:int=465, h:int=465){this.parent=parent;cont=new Sprite();parent.addChild(cont);list=new Vector.<Component>();this.w=w;this.h=h;fitComponents();cont.graphics.beginFill(0xD6E2D8);cont.graphics.drawRect(0, 0, w/Scale, h/Scale);cont.graphics.endFill();cont.graphics.beginFill(0x507256);cont.graphics.drawRect(w/Scale, 0,-2, h/Scale);cont.graphics.endFill();cont.scaleX=cont.scaleY=Scale;if(mobileSlideMenu){dragBox=new DragBox(30, 0x507256, 30, w-30, true, function():void{cont.x=-w*(1-dragBox.value);});dragBox.addEventListener('click', function(e:*):void{visible=!visible;});parent.addChild(dragBox);dragBox.y=h-30;visible=true;}}public function get visible():Boolean{return cont.x>-w*.65;}public function set visible(v:Boolean):void{cont.x=v?0 :-w;if(mobileSlideMenu)dragBox.value=v?1 : 0;}private function fitComponents(newComp:Component=null):void{if(newComp){list.push(newComp);}var yPos:Number=Margin/Scale;var c:Component;for(var i:int=0;i<list.length;i++){c=list[i];c.x=Margin/Scale;c.width=(w-(Margin*2))/Scale-2*Scale;c.y=yPos;c.draw();if(c is CheckBox)c.y+=Gap/Scale;else if(c is HUISlider)c.width+=25;yPos=c.y+c.getBounds(cont).height+Gap/Scale;}}}class DragPoint extends Sprite{public var dragBounds:Rectangle=null;public function styleAll(FillColor:uint=0x550200, Radius:Number=6, LineColor:uint=0xFB0600, LineThikness:Number=2, LineAlpha:Number=1, Alpha:Number=1):void{styleDown={lineThikness : LineThikness,lineColor : LineColor,lineAlpha : LineAlpha,fillColor : FillColor,radius : Radius,alpha : Alpha};styleStatic={lineThikness : LineThikness,lineColor : LineColor,lineAlpha : LineAlpha,fillColor : FillColor,radius : Radius,alpha : Alpha};styleNormal={lineThikness : LineThikness,lineColor : LineColor,lineAlpha : LineAlpha,fillColor : FillColor,radius : Radius,alpha : Alpha};}public var styleDown:Object=null;public var styleStatic:Object=null;public var styleNormal:Object=null;private var radius:Number=0;private var isStatic:Boolean;private var onMove:Function;public function DragPoint(onMove:Function=null , isStatic:Boolean=false){styleAll();this.onMove=onMove;this.isStatic=isStatic;useHandCursor=buttonMode=true;addEventListener('addedToStage', function(e:*):void{draw(isStatic?styleStatic : styleNormal);addEventListener('mouseDown', onMD);});}private function onMD(e:*):void{draw(styleDown);stage.addEventListener('mouseUp', onMU);stage.addEventListener('mouseMove', update);}private function update(e:MouseEvent):void{if(!isStatic)this.x=parent.mouseX;this.y=parent.mouseY;if(dragBounds){if(!isStatic){if(this.x-radius<dragBounds.x)this.x=dragBounds.x+radius;if(this.x+radius>dragBounds.right)this.x=dragBounds.right-radius;}if(this.y-radius<dragBounds.y)this.y=dragBounds.y+radius;if(this.y+radius>dragBounds.bottom)this.y=dragBounds.bottom-radius;}if(onMove !=null){if(onMove.length==1)onMove(this);else onMove();}}private function onMU(e:*):void{if(!stage)return;stage.removeEventListener('mouseUp', onMU);stage.removeEventListener('mouseMove', update);draw(isStatic?styleStatic : styleNormal);}public function draw(style:Object):void{graphics.clear();graphics.lineStyle(style.lineThikness, style.lineColor, style.lineAlpha);graphics.beginFill(style.fillColor);graphics.drawCircle(0, 0, style.radius);graphics.endFill();alpha=style.alpha;radius=style.radius+style.lineThikness/2;}}