Center a left-top corner based element in stage


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

just a basic center function


Copy this code and paste it in your HTML
  1. var el:MovieClip = new MovieClip;
  2.  
  3. el.addEventListener(Event.ADDED_TO_STAGE,center);
  4.  
  5. private function center(evt:Event):void{
  6. evt.target.x = (stage.stageWidth - evt.target.width)/2;
  7. evt.target.y = (stage.stageHeight - evt.target.height)/2;
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.