Paranoid Android
Paranoid Android

Reputation: 5037

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 clicks, so I am wondering how I can perform the same action only with code.

Upvotes: 3

Views: 11300

Answers (2)

dewhacker
dewhacker

Reputation: 71

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;

Upvotes: 1

anne
anne

Reputation: 31

myClip.x-= myClip.width/2;
myClip.y-= myClip.height/2;

Upvotes: 2

Related Questions