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

AS3 Source Code Compreser / Minifier / Single Line Generator

Copy past as3 source code to text field and click convert.
Get Adobe Flash player
by WLAD 03 Jan 2016

    Talk

    greentec at 04 Jan 2016 16:11
    like Javascript... and where to use it?
    WLAD at 07 Jan 2016 15:29
    don't know, don't care, i was bored... so i wrote some code :P
    greentec at 08 Jan 2016 04:25
    good. :-)
    Embed
/**
 * Copyright WLAD ( http://wonderfl.net/user/WLAD )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/wFdv
 */

// forked from WLAD's WFLPortalbe minifyed 
package {
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	[SWF(width = "465", height = "465" )]
	public class WFLPortable extends Sprite
	{
		public function WFLPortable() 
		{
			WG.INIT( stage );
			
			var G:int = 20;
			var BW:int = WG.W - G * 2;var BH:int = 60;
			var C:Canvas = new Canvas( this );C.DrawRect( 0x27364E, -BW/2, -BH/2, BW, BH );C.DrawText( "CONVERT", 0, 0, true, 0xFFFFFF, 24, -1 );C.display.x = WG.W2;C.display.y = WG.H - ( BH + G ) / 2 ;
			var T:TextField = new TextField();
			T.x = T.y = G;T.type = "input";T.width = WG.W - G*2;T.height = WG.H - G*2 - BH;T.multiline = T.wordWrap = true;T.defaultTextFormat = new TextFormat( "Courier", 18, 0xFFFFFF );T.text = "empty";addChild( T );T.background = true;T.backgroundColor = 0x0E131D;
			
			WG.onResize = function():void {
				
				T.width = WG.W - G*2;
				T.height = WG.H - G*2 - BH;
			};
			
			WG.onMouseDown = function():void {
				// If button were clicked 
				if ( mouseY > G * 2 + ( WG.H - G * 2 - BH) ) 
				{
					// Minify AS3 Code
					T.text = minify( minify( T.text ) );
					
				} // On buttonClick [end]
				
			}; // onMouseDown [end]
		}
	}
}

function minify( text:String ):String
{
	/* Known issue: Avoid using the 
	 * comment regex "//" inside a 
	 * string variable. e.g. "text text // text text"
	 * will only wite the following: 
	 * 		"text text 
	 * exclusing the comment regex and not closing the
	 * the string variable.
	 */
	
	// read input text
	var S:String = text;
	//var CI:int = 0; // will result in infinite loop in some cases
	var cStart:int = S.indexOf("/*");//S.indexOf("/*",CI);
	var cEnd:int = S.indexOf("*/");//S.indexOf("*/",CI);
	while ( cStart != -1 && cEnd != -1 && cStart < cEnd && cEnd < S.length ) 
	{
		S = S.substr(0, cStart) + " " + S.substr(cEnd + 2);
		// CI = cEnd;
		cStart = S.indexOf("/*");//S.indexOf("/*",CI);
		cEnd = 	S.indexOf("*/");//S.indexOf("*/",CI);
	}
	var AR:Array;
	// Check the input new line format and split it appropietly
	if ( S.indexOf( "\n" ) > -1 ) AR = S.split("\n"); 
	else if ( S.indexOf( "\r" ) > -1 ) AR = S.split("\r");
	// Else set the input text array as a single element array
	else AR = [ S ];
	// current text line from input text
	var L:String;
	// char at index i in line L
	var CR:String;
	// output text
	var TXT:String = "";
	// space detected flag
	var SPACE:Boolean;
	// char detected flag
	var CHAR:Boolean;
	// previous char
	var P:String;
	// next char
	var N:String;
	// check if charArgument ignores space
	var F:Function = function( charArgument:String ):Boolean
	{return ":=_+-*/<({[?]})>|&;^\"\'".indexOf( charArgument ) > 0};
	// Loop threw lines 	
	for ( var i:int = 0; i < AR.length; ++i ) {
		// Read current line
		L = AR[ i ];
		// Reset variables
		SPACE = false;
		CHAR = false;
		for ( var j:int = 0; j < L.length; ++j )
		{
			// Reset variables
			P = N = "";
			// Read characters 
			if ( j > 0 ) P = L.charAt(j-1);
			CR = L.charAt( j );
			if ( j < L.length - 1 ) N = L.charAt(j+1);
			
			// Trim white space 
			if ( CR == " " || CR == "\t" ) 
			{
				if ( SPACE ) continue;
				if ( F( P ) || F( N ) ) continue;
				if ( P == " " || P == "\t" ) continue;
				TXT += " ";
				SPACE = true;
				
				continue;
			}
			else SPACE = false;
			
			// Skip new lines 
			if ( CR == "\n" || CR == "\r" || CR == "" ) continue;
			
			// Skip single line comments 
			//if ( CR == "/" && CHAR ) continue;
			if ( CR == "/" && N == "/" ) break;
			
			// Write char into text
			TXT += CR;
			CHAR = true;
		}
		
	} // lines in text loop [end] 
	
	// Return value
	return TXT;
}

import flash.text.*;import flash.display.*;import flash.events.*;import flash.geom.*;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 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 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;}}