Skip to main content
Known Participant
June 15, 2011
Question

how to center a movieclip on a dynamic stage..?

  • June 15, 2011
  • 2 replies
  • 1559 views

I got a video background where I have a button (which is a movie clip) inside the button I need to have a movieclip to be centered on the stage. My stage is dynamic and therefore changes according to the browser of the user.

I tried the following:

notice.x=stage.stageWidth/2

notice.y=stage.stageHeight/2

but it places it almost out of the stage...

anyone who has a quick tip?

This topic has been closed for replies.

2 replies

Participating Frequently
June 15, 2011

If the movieclip you're trying to position is inside the button, its coordinates would be relative to the button, or whatever the clip's parent is. The clip's (0,0) would be the position of its parent. So, if the parent is at (50,50), and you tell the clip to go to (0,0), on the actual stage it would still be (50,50). You'd have to compensate for that.

So your code would be more like:

notice.x=stage.stageWidth/2 - parent.x

notice.y=stage.stageHeight/2 - parent.y

However, if the parent's parent isn't at (0,0) either...

Use this method carefully, there's probably a way to set the absolute coordinates too, so setting it's world or stage coords to (0,0), you could try looking into that. But, the possible root of your current problem is that the clip's parent coordinates are influencing it.

kimtragerAuthor
Known Participant
June 15, 2011

I tried subtracting the parent coordinates but doesn't seem to affect much, the parent is not (0,0) but not that far from... 

kglad
Community Expert
Community Expert
June 15, 2011

where's the registration point of notice and are you publishing for 100%x100%?

kimtragerAuthor
Known Participant
June 15, 2011

the registration point is in the middle of the object - what do you mean by publishing 100% x 100%?

kglad
Community Expert
Community Expert
June 15, 2011

use:

notice.x=stage.stageWidth/2-notice.width/2

notice.y=stage.stageHeight/2-notice.height/2

if notice is on the stage.  if it's nested, center its parent, too.