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: うぇー

動きました。よく見たらRectangleの数値が違ってました。
Get Adobe Flash player
by zahir 15 Sep 2009
/**
 * Copyright zahir ( http://wonderfl.net/user/zahir )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/aU0G
 */

/* 
 * 動きました。よく見たらRectangleの数値が違ってました。
 */
package{
	import flash.display.*;
	import flash.events.Event;
	import flash.filters.DropShadowFilter;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	
	[SWF(width = 465, height = 465, backgroundColor = 0xCCCCCC)]

	public class Scale9_test extends Sprite{
		private var o:Sprite;
		private var rect:Shape;
		private var _line:Shape;
		private var _scale:Number = 1.01;
		
		private var m:Matrix;
		
		public function Scale9_test(){
			var w:int = 100;
			var h:int = 100;
			var offset:int = 16;
			
			o = new Sprite();
			this.addChild( o );
			var s:Shape = new Shape();
			o.addChild( s );
			rect = new Shape();
			o.addChild( rect );
			_line = new Shape();
			o.addChild( _line );
			
			o.cacheAsBitmap = true;
			
			var g:Graphics = s.graphics;
			m = new Matrix();
			m.createGradientBox( w, h, 0.017453 * 90);
			g.lineStyle( 2 );
			g.lineGradientStyle("linear", [0x999999, 0x666666], [1,1] , [0, 255], m);
			g.beginGradientFill( "linear", [0x666666, 0x111111], [1,1] , [0, 255], m);
			g.drawRoundRect( 0,0, w, h, offset,offset);
			g.endFill();
			
			g = rect.graphics;
			g.lineStyle( 1 , 0x000066);
			g.beginGradientFill( "linear", [0x0099FF, 0x003399], [1,1] , [0, 255], m);
			g.drawRect( 0,0, w-offset*2, h-offset*2);
			g.endFill();
			rect.x = rect.y = offset;
			
			
			// すみません、数値が間違ってましたorz
			var r:Rectangle = new Rectangle( offset, offset, w - offset*2, h -offset*2);
			o.scale9Grid = r;
			
			g= _line.graphics;
			g.lineStyle( 1, 0x00FFFF, 0.8);
			
			// left
			g.moveTo( r.x, 0);
			g.lineTo(r.x, h);
			
			// right
			g.moveTo( r.x + r.width, 0);
			g.lineTo( r.x + r.width , h);
			
			// top
			g.moveTo( 0, r.y);
			g.lineTo( w , r.y);
			
			// bottom
			g.moveTo( 0, r.y + r.height);
			g.lineTo( w , r.y + r.height);
			
			rePos();
			
			this.addEventListener(Event.ENTER_FRAME, onEnter);
		}
		private function onEnter(e:Event):void{
			o.scaleX *= _scale;
			if( o.scaleX >= 2.0){
				_scale = 0.99;
			}
			if( o.scaleX <= 1.0){
				_scale = 1.01;
			}
			rePos();
		}
		private function rePos():void{
			o.x = (stage.stageWidth - o.width) >>1;
			o.y = (stage.stageHeight - o.height) >>1;
		}
	}
}