动态改变注册点

package gameTool {
	import flash.display.DisplayObject;
	import flash.geom.Point;
	public class DynamicRegistration {
		/**
		 *动态改变注册点 
		 */		
		private var target:DisplayObject;
		private var point:Point;
		public function DynamicRegistration(target:DisplayObject,point:Point){            
			this.target = target;
			this.point = point;
		}
		public function setProperty(key:String,value:Number):void{
			var oldPoint:Point = target.parent.globalToLocal(target.localToGlobal(point));
			if(key=="x"|| key=="y"){
				target[key] = value - point[key];
			}else{                
				target[key] = value;
				var newPoint:Point = target.parent.globalToLocal(target.localToGlobal(point));
				target.x += oldPoint.x - newPoint.x;
				target.y += oldPoint.y - newPoint.y;
			}
		}
		public function getProperty(key:String):Number{            
			var value:Number;            
			if(key=="x"||key=="y"){
				value = target[key] + point[key];
			}else{                
				value = target[key];            
			}
			return value;
		}
		
	}    
}

 最近发现所谓的改变注册点其实是做不到的.因为如果改变就应该在下一次new MC()的时候注册点已经改变.但实际并不是这样.只是在使用的时候模拟的计算了改变位置.

你可能感兴趣的:(Flash)