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

flash on 2010-1-16

完全パクリな上にグダグダー
元ネタ :: http://wonderfl.net/code/51d294497666431c9e88fde05acfd9c5fec0e8d8
Get Adobe Flash player
by zahir 15 Jan 2010
/**
 * Copyright zahir ( http://wonderfl.net/user/zahir )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/bEg1W
 */

/* 
	完全パクリな上にグダグダー
	元ネタ :: http://wonderfl.net/code/51d294497666431c9e88fde05acfd9c5fec0e8d8
 */
package{
	import flash.display.*;
	import flash.events.*;
	import flash.system.System;
	[SWF(width = "465", height = "465", backgroundColor="0x666666")]

	public class Wonderfl4Hatena extends Sprite{
		private var ezTxt:EzTextArea;
		
		private var clearBtn:MyBtn;
		private var convBtn:MyBtn;
		private var copyBtn:MyBtn;
		
		public function Wonderfl4Hatena(){
			addChild(new Title());
			ezTxt = new EzTextArea( this );
			ezTxt.width = 420;
			ezTxt.height = 300;
			ezTxt.update();
			
			ezTxt.x = (465 - 420) >> 1;
			ezTxt.y = 70;
			
			ezTxt.text = "ここにペースト";
			
			clearBtn = new MyBtn(this, "clear");
			convBtn = new MyBtn(this, "convert");
			copyBtn = new MyBtn(this, "copy");
			
			clearBtn.x = ezTxt.x + 25;
			copyBtn.x = clearBtn.x + clearBtn.width + 8;
			convBtn.x = copyBtn.x + copyBtn.width + 8;
			clearBtn.y = convBtn.y = copyBtn.y = 370;
			
			clearBtn.addEventListener( MouseEvent.CLICK, function(e:Event):void{
				ezTxt.text = "";
			});
			copyBtn.addEventListener( MouseEvent.CLICK, function(e:MouseEvent):void{
				System.setClipboard(ezTxt.text);
			});
			convBtn.addEventListener( MouseEvent.CLICK, convert);
			
			graphics.beginFill( 0x0 );
			graphics.drawRect(0,435, 465,465);
			graphics.endFill()
		}
		private function convert(e:MouseEvent):void{
			sendData();
		}
		public function sendData():void{
			var pattern:RegExp = /<iframe.*(src=\".*?\").*(width=\".*?\").*(height=\".*?\").*(style=\".*?\").*?>/;
			var str:String = ezTxt.text;
			ezTxt.text = str.replace(pattern, replace_func);
		}
		public function replace_func():String {
			var pattern_kayac:RegExp = /wonderfl\.net/;
			var str:String = arguments[1];
			str = str.replace(pattern_kayac, "wonderfl.kayac.com");
			return "<iframe " + str + arguments[2] + arguments[3] + arguments[4] + ">";
		}
	}
}

import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Shape;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.text.TextField;
import flash.display.DisplayObjectContainer;
import flash.display.Loader;
import flash.events.Event;
import flash.display.Bitmap;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.text.TextFormat;
import flash.events.MouseEvent;
import flash.filters.GlowFilter;
import flash.filters.DropShadowFilter;
import flash.text.TextFieldType;
import flash.events.FocusEvent;
import mx.controls.Text;
class Title extends Sprite{
	public function Title(){
		var g:Graphics = this.graphics;
		var m:Matrix = new Matrix();
		m.createGradientBox(465,50, 0.01745 * 90);
		g.beginGradientFill("linear", [0x333333, 0x222222, 0x111111, 0xCCCCCC], [1, 1, 1, 1], [0, 64, 240, 255], m);
		g.drawRect(0,0,465, 50);
		g.endFill();
		
		var _t:TextField = new TextField();
		addChild(_t);
		_t.autoSize = "left";
		_t.text = "wonderfl 4 Hatena";
		
		_t.setTextFormat( new TextFormat("georgia", 26, 0x999999, true), 0, 6);
		_t.setTextFormat( new TextFormat("georgia", 26, 0xCC3333, true), 6, 8);
		_t.setTextFormat( new TextFormat("georgia", 26, 0x999999, true), 8, _t.length);
		
		_t.cacheAsBitmap = true;
		
		var gf:GlowFilter = new GlowFilter(0,0.4);
		gf.inner = true;
		_t.filters = [ gf , new GlowFilter(0xCCCCCC, .8, 2,2, 6, 3)];
		_t.x = 8;
		_t.y = (48 - _t.height) >> 1;
		
		filters = [ new DropShadowFilter(2, 90, 0, 0.4,8, 8, 2, 3)];
	}
}
class MyBtn{
	private var over_flg:Boolean = false;
	private var s:Sprite;
	private var _t:TextField;
	private var color:Array = [0x666666, 0xFF9900, 0x0099FF];
	private var textColor:Array = [0xCCCCCC, 0xFFFFFF, 0x666666];
	public function MyBtn(	parent:DisplayObjectContainer ,
											label:String){
		parent.addChild( (s = new Sprite()) );
		s.addChild( (_t = new TextField() ) );
		
		_t.text = label;
		_t.setTextFormat( new TextFormat("georgia", 12, 0xCCCCCC, true));
		_t.autoSize = "left"
		
		s.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
		s.addEventListener(MouseEvent.MOUSE_OVER, onOver);
		draw();
	}
	public function addEventListener(type:String,listener:Function):void{
		s.addEventListener(type, listener);
	}
	public function removeEventListener(type:String,listener:Function):void{
		s.removeEventListener(type, listener);
	}
	public function get x():int{ return s.x; }
	public function set x( value:int ):void{ s.x = value;}
	public function get y():int{ return s.y; }
	public function set y( value:int ):void{ s.y = value;}
	
	public function get width():int{ return s.width; }
	public function get height():int{ return s.height; }
	
	private function onDown(e:MouseEvent):void{
		s.addEventListener(MouseEvent.MOUSE_UP, onUp);
		draw(2);
	}
	private function onUp(e:MouseEvent):void{
		s.removeEventListener(MouseEvent.MOUSE_UP, onUp);
		over_flg ? draw(1) : draw();
	}
	private function onOver(e:MouseEvent):void{
		s.addEventListener(MouseEvent.MOUSE_OUT, onOut);
		over_flg = true;
		draw(1);
	}
	private function onOut(e:MouseEvent):void{
		s.removeEventListener(MouseEvent.MOUSE_OUT, onOut);
		over_flg = false;
		draw();
	}
	
	private function draw( mode:int = 0):void{
		var g:Graphics = s.graphics;
		g.clear();
		var m:int = 0;
		var w:int = _t.width  + 24;
		var h:int = _t.height + 6;
		
		_t.x = (w - _t.width )>>1;
		_t.y = (h - _t.height)>>1;
		_t.textColor = textColor[mode];
		
		roundRect(g, 0x111111, m,m++, w, h, 3);
		roundRect(g, color[mode], m,m++, w-=2, h-=2, 3);
		roundRect(g, 0x111111, m,m++, w-=2, h-=2, 3);
		s.filters = [ new GlowFilter(color[mode], .4, 8,8, 2, 3) ];
	}
	private function rect( g:Graphics, color:uint, x:int, y:int, width:int, height:int):void{
		g.beginFill( color );
		g.drawRect(x,y, width, height);
		g.endFill();
	}
	private function roundRect( g:Graphics, color:uint, x:int, y:int, width:int, height:int, ellipse:int):void{
		g.beginFill( color );
		g.drawRoundRect(x,y, width, height, ellipse, ellipse);
		g.endFill();
	}
}

class EzTextArea{
	private var url:String = "http://zahir.coresv.com/wonderfl/img/scalingBitmapTest.png";
	
	private var loader:Loader;
	
	private var container:Sprite;
	private var bg:ScalingBitmap;
	private var t:TextField;
	
	private var parent:DisplayObjectContainer;
	
	private var _width:int, _height:int;
	
	public function EzTextArea( parent:DisplayObjectContainer , width:int = 200, height:int=200){
		this.parent = parent;
		_width = width;
		_height = height;
		t = new TextField();
		t.width = _width;
		t.height = _height;
		t.defaultTextFormat = new TextFormat("_ゴシック",10);
		
		parent.addChild( (bg = new ScalingBitmap(new BitmapData(_width, _height, true, 0)) ) );
		loader = new Loader();
		loader.contentLoaderInfo.addEventListener( Event.COMPLETE, loadComp);
		loader.load(new URLRequest(url), new LoaderContext(true));
		
		bg.addChild( (container = new Sprite())  );
		container.addChild( t );
		
		bg.addEventListener( "draw", function(e:Event):void{
			container.width = bg.innerWidth;
			container.height = bg.innerHeight;
		});
		
		t.textColor = 0x999999;
		t.type = TextFieldType.INPUT;
		t.wordWrap = t.alwaysShowSelection = t.selectable = true;
		
		t.addEventListener( FocusEvent.FOCUS_IN, function(e:FocusEvent):void{
			t.addEventListener(FocusEvent.FOCUS_OUT, outFocus);
			t.setSelection(0, t.text.length);
			t.textColor = 0xCCCCCC;
		});
		
		
	}
	private function outFocus(e:FocusEvent):void{
		t.removeEventListener(FocusEvent.FOCUS_OUT, outFocus );
		t.textColor = 0x999999;
	}
	
	public function get width():int{ return bg.width; }
	public function set width( value:int ):void{ bg.width = value; }
	
	public function get height():int{ return bg.height; }
	public function set height( value:int ):void{ bg.height = value; }
	
	public function get x():int{ return bg.x; }
	public function set x( value:int ):void{ bg.x = value; }
	
	public function get y():int{ return bg.y; }
	public function set y( value:int ):void{ bg.y = value; }
	
	public function get text():String{ return t.text; }
	public function set text( value:String ):void{ t.text = value; }
	
	public function slice(left:int = 0, top:int = 0, right:int = 0, bottom:int = 0):void{
		bg.left = left;
		bg.right = right;
		bg.top = top;
		bg.bottom = bottom;
	}
	public function update():void{
		bg.update();
	}
	private function loadComp(e:Event):void{
		loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadComp);
		bg.bitmapData = (loader.content as Bitmap).bitmapData;
		slice(40,40,40,40);
		update();
	}
}

class ScalingBitmap extends Sprite{
	private var $bitmapData$:BitmapData;
	private var $smooth$:Boolean = false;
	
	private var $bottom$:int = 0;
	private var $left$:int = 0;
	private var $right$:int = 0;
	private var $top$:int = 0;
	
	protected var w:int;
	protected var h:int;
	
	protected var newWidth:int;
	protected var newHeight:int;
	
	
	public function ScalingBitmap(	bitmapData:BitmapData,
														left:int = 0, top:int = 0, right:int = 0, bottom:int = 0,
														smooth:Boolean = false){
		this.bitmapData = bitmapData.clone();
		
		this.left = left;
		this.top = top;
		this.right = right;
		this.bottom = bottom;
		this.smooth = smooth;
		
		width = w;
		height = h;
		update();
	}
	
	public function get bottom():int{
		return $bottom$;
	}
	public function set bottom( value:int ):void{
		$bottom$ = (value < 0) ? 0 : value;
	}
	
	public function get left():int{
		return $left$;
	}
	public function set left( value:int ):void{
		$left$ = (value < 0) ? 0 : value;
	}
	
	public function get right():int{
		return $right$;
	}
	public function set right( value:int ):void{
		$right$ = (value < 0) ? 0 : value;
	}
	
	public function get top():int{
		return $top$;
	}
	public function set top( value:int ):void{
		$top$ = (value < 0) ? 0 : value;
	}
	
	public function get innerHeight():int{
		return ( newHeight - ( top + bottom ) );
	}
	public function get innerWidth():int{
		return ( newWidth - ( left + right ) );
	}
	
	public function get bitmapData():BitmapData{
		return $bitmapData$;
	}
	public function set bitmapData( value:BitmapData ):void{
		$bitmapData$ = value;
		w = bitmapData.width;
		h = bitmapData.height;
	}
	
	public function get smooth():Boolean{
		return $smooth$;
	}
	public function set smooth( value:Boolean ):void{
		$smooth$ = value;
	}
	
	protected function get g():Graphics{ return super.graphics; }
	override public function get graphics():Graphics{ return null }
	override public function addChild(child:DisplayObject):DisplayObject{
		super.addChild( child );
		child.x = left;
		child.y = top;
		return child;
	}
	
	override public function set scale9Grid(innerRectangle:Rectangle):void{}
	
	override public function set height(value:Number):void{
		var n:int = top + bottom;
		value = (value < 0) ? 0 : value;
		value = (value < n) ? n :value;
		newHeight = value;
	}
	override public function set width(value:Number):void{
		var n:int = left + right;
		value = (value < 0) ? 0 : value;
		value = (value < n) ? n :value;
		newWidth = value;
	}
	
	public function update():void{
		var offsetX:int = w - ( left + right );
		var offsetY:int = h - ( top + bottom );
		scale9Grid = new Rectangle(left, top, offsetX,offsetY);
		
		resizeChild();
		draw();
	}
	protected function resizeChild():void{
		var len:int = this.numChildren;
		while(len){
			len--;
			var d:DisplayObject = getChildAt( len );
			d.x = left;
			d.y = top;
			d.width = innerWidth;
			d.height = innerHeight;
		}
	}
	protected function draw():void{
		var iw:Number = w - ( left + right );
		var ih:Number = h - ( top + bottom );
		
		var _sx:Number = innerWidth / iw;
		var _sy:Number = innerHeight / ih;
		
		var offsetX1:Number = left - left * _sx;
		var offsetX2:Number = newWidth % w;
		
		var offsetY1:Number = top - top * _sy;
		var offsetY2:Number = newHeight % h;
		
		var r:int = newWidth - right;
		var b:int = newHeight - bottom;
		
		g.clear();
		
		// top
		drawRect(0,0, left,top );
		drawRect(left,0, innerWidth,top, createBox( _sx, 1, offsetX1, 0) );
		drawRect(r,0, right,top, createBox( 1, 1, offsetX2, 0 ) );
		
		// middle
		drawRect(0,top, left, innerHeight, createBox(1,_sy, 0,offsetY1 ) );
		drawRect(left,top, innerWidth, innerHeight, createBox(_sx,_sy,offsetX1, offsetY1 ) );
		drawRect(r,top, right, innerHeight, createBox(1,_sy, offsetX2,offsetY1 ) );
		
		// bottom
		drawRect(0, b, left,top , createBox(1,1, 0, offsetY2));
		drawRect(left,b, innerWidth,top, createBox( _sx, 1, offsetX1, offsetY2 ) );
		drawRect(r,b, right,top, createBox( 1, 1, offsetX2, offsetY2 ) );
		
		this.dispatchEvent(new Event("draw"));
	}
	
	
	protected function drawRect( _x:int, _y:int, _width:int, _height:int, matrix:Matrix = null ):void{
		g.beginBitmapFill( bitmapData, matrix, true, smooth );
		g.drawRect( _x, _y, _width,_height );
		g.endFill();
	}
	
	protected function createBox( scaleX:Number = 1, scaleY:Number = 1, offsetX:Number = 0, offsetY:Number = 0):Matrix{
		var m:Matrix = new Matrix();
		m.scale( scaleX, scaleY );
		m.translate( offsetX, offsetY );
		return m;
	}
	//
}