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.
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.
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();
My recommendation to the old registration point problem, few things...
If you MUST use AS3 to dynamically reposition it...
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.