AS3 Center one DisplayObject relative to another


/ Published in: ActionScript 3
Save to your folder(s)

Taken from Christian Cantrell's Adobe article called 'Authoring mobile Flash content for multiple screen sizes'.


Copy this code and paste it in your HTML
  1. function center(foreground:DisplayObject, background:DisplayObject):void
  2. {
  3. foreground.x = (background.width / 2) - (foreground.width / 2);
  4. foreground.y = (background.height / 2) + (foreground.height / 2);
  5. }

URL: http://www.adobe.com/devnet/flash/articles/authoring_for_multiple_screen_sizes.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.