views:

60

answers:

2

Hello!

I have a MC in an AS3 animation and I want to increase its height from bottom to top which would mean that the registration point should be bottom of the MC and center of width (horizontal center).

How can I do this please?

Thank you.

+1  A: 

ah, the old registration point problem. :)

i once saw a small custom class that allowed you to change the registration point of your display object, as you can simply do in Flash Authoring. google around if you're curious.

the solution is rather easy, though. the registration point of display objects is assigned based on how the object is added to the display list. you just have to take that into account when your are adding the display object to the display list, then set up a bit of easy math to change the registration point:

//Set up rect's width and height
var rectWidth:uint = 200;
var rectHeight:uint = 100;

//Assign registration point (TL, TC, TR, CL, C, CR, BL, BC, BR = top, center, bottom, left, right)
var registration:String = "C"

//Assign rect's X and Y properties
var rectX:int;
var rectY:int;

switch (registration)
       {
       case "TL": rectX = 0;
                  rectY = 0;
                  break;

       case "TC": rectX = -rectWidth / 2;
                  rectY = 0;
                  break;

       case "TR": rectX = -rectWidth;
                  rectY = 0;
                  break;

       case "CL": rectX = 0;
                  rectY = -rectHeight / 2;
                  break;

       case "C":  rectX = -rectWidth / 2;
                  rectY = -rectHeight / 2;
                  break;

       case "CR": rectX = -rectWidth;
                  rectY = -rectHeight / 2;
                  break;

       case "BL": rectX = 0;
                  rectY = -rectHeight;
                  break;

       case "BC": rectX = -rectWidth / 2;
                  rectY = -rectHeight;
                  break;

       case "BR": rectX = -rectWidth;
                  rectY = -rectHeight;
       }


//Draw the rect
var rect:Sprite = new Sprite();
rect.graphics.beginFill(0xFF0000);
rect.graphics.drawRect(rectX, rectY, rectWidth, rectHeight);
rect.graphics.endFill();
TheDarkInI1978
Haha, yup, the old registration point problem. :) Thank you for your answer, excellent.
Francisc
+1  A: 

My recommendation to the old registration point problem, few things...

  • If you can edit the symbol and you only have a few to process, honestly - do it manually.
  • If you have quite a handful to process but still could hire monkeys to re-position the symbols, consider looking into JSFL scripts to batch process your selection of Library symbols.
  • If you MUST use AS3 to dynamically reposition it...

    • And you don't mind putting the object into another container, put it into a new Sprite object at a location where its bottom center meets the (0,0) location, then you can scale the sprite container instead of your asset.
    • And you don't mind sacrificing vector quality for a BitmapData snapshot of your asset, take a snapshot of your asset (as it would appear "fully opened / stretched), crop the bitmap (by using a combination of:

    var rect:Rectangle = bitmapData.getColorBoundsRect(0xff000000, 0, false); yourCroppedBitmapData.copyPixels( bitmapData, rect, ... );

    ... once you have a reliable top-left cornered registration point, you can do the math to position this Bitmap in a Sprite container (as above) to scale it upwards.

Or... hiring monkeys would be fun too :P

But yeah, those are some of the alternate ways you can reposition the symbols.

bigp
Thank you, bigp. I was hoping there is an AS3 method of doing this as you would when you move the rotation point with the Transform Tool (Q).
Francisc
Yeah, not that I'm aware of. It seems to be a Flash IDE design tool only. Weird enough they support customizing the 9-slice grid at runtime with AS3.
bigp
Just thought of something, could the object's ".scrollRect" property be used? (Not sure if it would lead to worst problems though, like clipping)
bigp