# Center videos dynamically at runtime

**URL:** <https://forum.kirupa.com/t/center-videos-dynamically-at-runtime/315352>\
**Category:** flash\
**Created:** [October 23, 2010, 8:37pm UTC](https://forum.kirupa.com/t/center-videos-dynamically-at-runtime/315352 "2010-10-23T20:37:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike8](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Mike8](https://forum.kirupa.com/u/Mike8)\
**Post date:** [October 23, 2010, 8:37pm UTC](https://forum.kirupa.com/t/center-videos-dynamically-at-runtime/315352/1 "2010-10-23T20:37:58Z")

</div>

Hi

I have a presentation with various embedded and external videos linked to it. I need them to be positioned in the center of the screen no matter what resolution the user is running, therefore I need to position them dynamically and not with specific co-ordinates. I have found a link and some code that does this, but its a big chunk of code and I would like to put this code in my main .as file, as a function, and then in my main timeline when I have a video - just use one line of code to call the function and apply it to a movieclip with the video inside.

Here is the link :[http://scriptplayground.com/tutorials/as/Center-a-movieclip-on-stage-resize-in-AS3/](http://scriptplayground.com/tutorials/as/Center-a-movieclip-on-stage-resize-in-AS3/)

and here is the code :

```auto
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;

function resizeHandler(e:Event):void
{
  mySampleMC.x = (mySampleMC.stage.stageWidth / 2) - (mySampleMC.width / 2);
  mySampleMC.y = (mySampleMC.stage.stageHeight / 2) - (mySampleMC.height / 2);
}

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, resizeHandler);

stage.dispatchEvent(new Event(Event.RESIZE));

```

As you can see, the function has the reference to a specific movieclip instance variable inside it. I need to change this so that its generalized, does the same thing but instead I pass a movieclip as a parameter ? So this block of code would be in my main.as file just once, then on my main timeline when I need to link to a video I call this function somehow with one line of code but apply it to a certain movieclip. ie: so I dont need to write out this whole block of code for every movieclip with a video inside.

Any help is greatly appreciated, thanks in advance…
