Set MovieClip registration point to center in AS3

Is it possible to set the registration point of MovieClip (or another display object) to the center when creating in AS3?

following

var myClip:MovieClip  = new MovieClip();

sets the registration point myClip in the upper left corner by default. Using Flash CS4 to install it in the center is just a few clicks, so I wonder how I can perform the same action with only the code.

+3
source share
2 answers
myClip.x-= myClip.width/2;
myClip.y-= myClip.height/2;
+2
source

This is not true where _clip is your MovieClip using this code:

var dpObj = _clip.getChildAt(0); //the dipslay object or graphic you movie clip contains
var mat:Matrix = dpObj.transform.matrix;
var bounds:Rectangle = _clip.getBounds(dpObj); // get the bounds relative to the movie clip
mat.tx = -bounds.left; //left and top will be the registration point of the clip
mat.ty = -bounds.top;
+1
source

Source: https://habr.com/ru/post/1738848/


All Articles