my space:http://www.laaan.cn

dynamic registration point of flash

In flash, the display object has a lot of properties. Such as width, height, rotation, alpha and so on. Recently, i have been writting a class to control display object with dynamic registration. here is the demo: It takes me a lot of time. So i think I should recode something that you should pay attention to. 1: the registration point in mc is  always to be (0, 0). So, when you set the width/height/rotation property of a mc, the mc changes according to point(0, 0). To dynamic set registration point doesnot change the real registration point BUT let the mc looks like. 2:I change the x and y properties of the mc to let it look like been changed registration point: //dynamic set mc's registration point to (20, 20); var globalPoint:Point = mc.localToGlobal(new Point(20, 20)); //control the mc. mc.width += 100; mc.height += 50; mc.rotaion += 10; //move mc to fit the original point var nowGlobalPoint:Point = mc.localToGlobal(new Point(20, 20)); mc.x += globalPoint.x - nowGlobalPoint.x; mc.y += globalPoint.y - nowGlobalPoint.y; 3:the flex component is not so easy to do that. You must notice that. When you change the component's properties(width/height/rotation...), the component do update immediately. So, the code here is just for flash. 4:size control of mc. get the original size of mc: var size:Rectangle = mc.getRect(mc); get current size of mc: var tmp:Number = mc.rotation; mc.rotation = 0;//make sure the mc's rotation property is 0 var currentSize:Rectangle = mc.getRect(mc.parent); mc.rotation = tmp; set the mc's size: var tmp:Number = mc.rotation; mc.rotation = 0; mc.width += 30; mc.height = 50; mc.rotation = tmp; 5:scale and size is the same thing in flash. That is, if you change the mc's width/height, the scaleX /scaleY will change too. But to flex components, it's not. 6:the simplest way to change the rotation property of a mc accoding to you mouse position is that: var rp:Point = mc.localToGlobal(new Point(0, 0)); var ro:Number = Math.atan2(stage.mouseY - rp.y, stage.mouseX - rp.x); mc.rotation = Math.round(ro / Math.PI * 180)  [ + N];// N is a indent value. …… be careful...
posted @ 2008-12-10 15:49  laan  阅读(173)  评论(0编辑  收藏  举报
my space:http://www.laaan.cn