We help IT Professionals succeed at work.

How to center align an flv video in FLVPlayback

guswebb asked
Medium Priority
Last Modified: 2013-11-11
I have an FLVPlayback on stage defined as W:510.0 and H:286.9 (16:9 aspect ratio) and a video i am loading into the swf with dimensions W:368 x H:208 (also 19:9). When the video loads into the defined FLVPlayback video it loads with its original dimensions to the far left with a massive black area to the right of the video.My questions are:
1- Is it not possible to center align the video within the FLVplayback?
2- Since they are both 16:9 cant i just make the video take up the full FLVPlayback area defined?
Code is AS2.
Watch Question

3 easy steps.

1. Make a black square movieclip.  
2. Set it to the size you want.  
3. Position the resized FLV video in the center of it.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Here is some code I found that my illuminate things for you.

           attachMovie("FLVPlayback", "my_FLVPlybk", 10, {width:320, height:240, x:90, y:100});
            //center the FLVPlayback component when FLV is ready to play
            var listenerObject:Object = new Object();
            listenerObject.resize = function(eventObject:Object):Void {
                //center video in playback area
                newx = (460 - my_FLVPlybk.preferredWidth)/2;
                newy = (470 - my_FLVPlybk.preferredHeight)/2;
                my_FLVPlybk._x = newx;
                my_FLVPlybk._y = newy;
            my_FLVPlybk.addEventListener("resize", listenerObject);    
            listenerObject.ready = function(eventObject:Object):Void {
                my_FLVPlybk.setSize(250, 350);


I am going to be dynamically passing in different sized videos so that approach will not work, the case about the video size i mentioned was only an example. Im might want to pass in a video of aspect ratio 3:4 in which case your idea will not make it centered, i am looking for some actionscript code. (for both of my questons)


Your code is moving the whole FLVPlayback, i dont want to do that, surely there must be a way by something like this:
FLVideo.scaleMode = VideoScaleMode.NO_SCALE;
FLVVideo.align = VideoAlign.CENTER;
// these dont work however


Ok after alot of looking around this is what ive come up with:

1- There is no simple centering of video within flvplayback so ill have to use brittonv's reposition solution.

2- Since they are both 16:9 cant i just make the video take up the full FLVPlayback area defined?
After i did my own testing: Yes by setting the autosize of the flvplayback to false and setting maintainaspect ratio to true + it might be best to make sure all the videos are 16:9 aswell.


This reassures me that the only probable way is to reposition the FLVplayback which answers part 1 of my question.
I was having a similar issue I have an application that has videos encoded at 400 x 300 and 480 x 270.

Flash CS3 encoder embeds all kinds of goodies into the metadata of the video; older FLV files will have the height and width only.

Here's what I did.
Followed adobe's metadata example http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00003022.html 

And added a switch statement to change the x position of myFLV based on what the metadata.

Hope that helps - works like a charm for me.

import mx.video.*;
var listenerObject:Object = new Object();
listenerObject.metadataReceived = function(eventObject:Object):Void {
        trace("canSeekToEnd is " + myFLV.metadata.canSeekToEnd);
        trace("Number of cue points is " + myFLV.metadata.cuePoints.length);
        trace("Frame rate is " + myFLV.metadata.framerate);
        trace("Height is " + myFLV.metadata.height);
        trace("Width is " + myFLV.metadata.width);
        trace("Duration is " + myFLV.metadata.duration + " seconds");
        var vidWidth:Number = myFLV.metadata.width;
		switch(vidWidth) {
			case 480:
                        //stage width is 500 myFLV
			myFLV._x = 10;
			case 400:
			myFLV._x = 50;
myFLV.addEventListener("metadataReceived", listenerObject);
myFLV.contentPath = "http://www.helpexamples.com/flash/video/cuepoints.flv";

Open in new window

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.