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

コロコロ

...
@author ...
// forked from mtok's 任意の点を中心に回転させる。サンプル
package  
{
	import caurina.transitions.properties.DisplayShortcuts;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import caurina.transitions.Tweener;
	import flash.geom.Rectangle;
	import flash.utils.Dictionary;
	/**
	 * ...
	 * @author ...
	 */
	public class CoroCoro extends Sprite
	{
		private var boxes:Array;
		private var mat:Matrix;
		private var flags:Dictionary;
		public function CoroCoro() 
		{
			addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);;
		}
		
		private function addedToStageHandler(e:Event):void 
		{
			removeEventListener(e.type, arguments.callee);
			
			flags = new Dictionary(true);
			boxes = new Array();
			var box:DisplayObject;
			for (var i:int = 0; i < 9; i++) {
				box = createBox(50, 50);
				box.y = 50 * i;
				addChild(box);
				boxes.push(box);
			}
		}
		private function createBox(w:Number, h:Number):DisplayObject {
			var mc:Sprite = new Sprite();
			mc.graphics.beginFill(0xffffff);
			mc.graphics.drawRect(0, 0, w, h); 
			mc.graphics.endFill();
			mc.graphics.beginFill(0xFD5322);
			mc.graphics.drawRect(2.5, 2.5, w-5, h-5); 
			mc.graphics.endFill();
			mc.graphics.beginFill(0xFFFFFF);
			mc.graphics.drawCircle(w*0.5, w*0.2, 5);
			mc.graphics.endFill();
			mc.buttonMode = true;
			mc.useHandCursor = true;
			mc.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
			return mc;
		}
		private function mouseDownHandler(e:MouseEvent):void 
		{
			var d:DisplayObject = e.target as DisplayObject;
			startRotation(d);
		}
		
		public function startRotation(target:DisplayObject):void {
			if (Tweener.isTweening(flags[target])) {
				trace('is tweening');
				return;
			}
			var obj:Object = { angle:0 };
			flags[target] = obj;
			Tweener.addTween(obj, { angle:Math.PI*0.5, time:0.5, transition:"easeInOutCubic",
				onStart:function():void {
					var rect:Rectangle = target.getRect(target.parent);
					this.matrix = target.transform.matrix;
					this.p = new Point(rect.x + rect.width, rect.y + rect.height);
					trace('start',this.p);
				},
				onUpdate:function():void {
					//trace('this', this.angle);
					var mat:Matrix = new Matrix();
					mat.translate( -this.p.x, -this.p.y);
					mat.rotate(this.angle);
					mat.translate(this.p.x, this.p.y);
					var orgMat:Matrix = obj.matrix.clone();
					orgMat.concat(mat);
					target.transform.matrix = orgMat;
				},
				onComplete:function():void  {
					var rect:Rectangle = target.getRect(target.parent);
					if (rect.x < stage.stageWidth - rect.width*2){
						Tweener.removeTweens(this);
						startRotation(target);
					}
				}
			});
		}
		
		private function rotateAt(d:DisplayObject, angle:Number, p:Point):void {
			var m:Matrix = d.transform.matrix;
			var m2:Matrix = new Matrix();
			m2.translate( -p.x, -p.y);
			m2.rotate(angle);
			m2.translate(p.x, p.y);
			m.concat(m2);
			d.transform.matrix = m;
		}
	}
}