Skip to main content
markerline
Inspiring
August 28, 2013
Question

center movie clips dynamically, as3.0

  • August 28, 2013
  • 1 reply
  • 3092 views

Hi.  I have seen this discussed both on Adobe Forums and other sites but I can't seem to make sense of the code supplied by what I have seen thus far.

I am trying to center display objects that are added to the stage at runtime dynamically through a basic drawing application.

the code is something like this:

1. add an event listener for the drawing event.

2. add the path you want to draw to a container movie clip on the stage.

3. add an enter-frame event listener to change the scale of the path randomly .... and this is the moment i want to change the default top,left registration point to the center,center of the path.  each path has its own registration point as i can tell thus far but at this point the scale is happening from the top,left of the container rather than about the path's own self.  and if it were to happen about the path i would have to get the bounds of the path and do some averaging to center the registration point.

unfortunately i don't know what the code looks like to achieve what i'm trying to get.

any help is appreciated.  thanks in advance.

This topic has been closed for replies.

1 reply

sinious
Legend
August 28, 2013

You're letting a user draw a path and then you're adding that to a container clip? If that's all you're doing (and each path has a container) then the x/y of the shape drawn should just be negated half the height and width in the container to be center registration.

Psuedo code e.g.

myContainer.addChild(myShapeDrawn);

myShapeDrawn.x -= myShapeDrawn.width / 2;

myShapeDrawn.y -= myShapeDrawn.height / 2;

Whatever you're bundling in the drawn object just needs to move itself half the width and height of itself inside the container to center itself in the container. Then you have center registration.

markerline
Inspiring
August 28, 2013

That's close sinious.  I guess some of the explanation got lost in its length.  Each shape is a new independent Display Object but they all are being drawn on the same container Movie Clip.  How would the code look in that case?

Thanks for the reply by the way.