Laan's steps..

Feed Rss

dynamic registration point of flash

12.10.2008, flash, my works, by .

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…

dynamic registration point of flash 有 5 条回应

  1. 很好,很强大。也详细。
    虽然俺一直用TransformTool,呵呵~

    回复
  2. 了哥,虽然我不懂as

    但是我知道这个演示很强大。
    第一次看到

    回复
  3. 嘿嘿 很不错

    回复
  4. What about it will tell?
    You will not prompt to me, where I can read about it?
    Between us speaking, in my opinion, it is obvious. I will refrain from comments.
    Yes, really. And I have faced it. Let’s discuss this question.
    It is very a pity to me, I can help nothing to you. But it is assured, that you will find the correct decision.

    回复

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>