Center movieclip on point

孤街浪徒 提交于 2019-12-24 17:25:03

问题


I'm dynamically loading movie clips (SWFS) into attached clips (from the library). The loaded movies don't all have center points, meaning that their registration point isn't directly in its center. This poses a problem when I load them into the attached clips, because they don't center on the attached clips, which is what I want them to do. Is there a way to center a movieclip based on width and height instead of registration point?

Thanks in advance!


回答1:


Use getBounds.

var bounds:Rectangle = loadedClip.getBounds(loadedClip);

bounds.x and bounds.y will be {0,0} for a top left aligned movie clip. Any other value tells you how much off center it is.

If your loaded clip is loadedClip and its parent is containerClip, the following will work.

loadedClip.x = (container.width - loadedClip.width)/2 - loadedClip.getBounds(loadedClip).x;
loadedClip.y = (container.height - loadedClip.height)/2 - loadedClip.getBounds(loadedClip).y;

If the clips involved in this have been scaled, then you have to adjust for the scaling as follows:

loadedClip.x = (container.width - loadedClip.width) / 2 - (loadedClip.getBounds(loadedClip).x * loadedClip.scaleX);
loadedClip.y = (container.height - loadedClip.height) / 2 - (loadedClip.getBounds(loadedClip).y * loadedClip.scaleY);

I hope this helps.




回答2:


You could just change the registration point of the MC to be centered using this class: Dynamic MovieClip Registration with AS2




回答3:


When the load completes, you can get the width and height of the loaded movies, and adjust the x & y position accordingly:

function onLoadComplete(){
 loadedmc._x = loadedmc._width/2 * -1;
 loadedmc._y = loadedmc._height/2 * -1;
}


来源:https://stackoverflow.com/questions/2375231/center-movieclip-on-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!