Set registration point of a MovieClip to its center in AS3
Can I set the registration point of a MovieClip (or other Display Object) to its center upon creation in AS3?
the following
var myClip:MovieClip = new MovieClip();
sets the registration point of myClip to its top left corner by default. Using Flash CS4 to set it to its center is just a couple of c开发者_StackOverflow社区licks, so I am wondering how I can perform the same action only with code.
myClip.x-= myClip.width/2;
myClip.y-= myClip.height/2;
That is not correct, where _clip is your MovieClip use 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;
精彩评论