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 ...
Get Adobe Flash player
by mtok 02 Feb 2009
package  
{
	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;

	/**
	 * ...
	 * @author ...
	 */
	public class Rotation extends Sprite
	{
		private var mc:MovieClip;
		private var mat:Matrix;
		private var p:Point;
		public function Rotation() 
		{
			addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);;
		}
		
		private function addedToStageHandler(e:Event):void 
		{
			removeEventListener(e.type, arguments.callee);
			stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
			mc = new MovieClip();
			mc.graphics.beginFill(0xffffff);
			mc.graphics.drawRect(0, 0, 50, 50); 
			mc.graphics.endFill();
			mc.graphics.beginFill(0xFD5322);
			mc.graphics.drawRect(2.5, 2.5, 45, 45); 
			mc.graphics.endFill();
			mc.graphics.beginFill(0xA4F32C);
			mc.graphics.drawCircle(25, 10, 5);
			mc.graphics.endFill();
			
			addChild(mc);
			
			p = new Point();
		}
		
		private function mouseDownHandler(e:MouseEvent):void 
		{
			p.x = mouseX, p.y = mouseY;
			startRotation();
			stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
		}
		
		private function mouseUpHandler(e:MouseEvent):void 
		{
			removeEventListener(e.type, arguments.callee);
			stopRotation();
		}
		public function startRotation():void {
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}
		
		private function enterFrameHandler(e:Event):void 
		{
			rotateAt(mc, Math.PI * 0.1, p);	
		}
		public function stopRotation():void {
			removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}
		
		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;
		}
	}
}