4 Replies Latest reply on Jan 18, 2011 9:58 PM by tjay99

    Aligning video to stage as2


      Hi Guys,


      I've got an swf which is loading in an .flv using the FLVPlayback component, but what I would like is for the component to be centered on stage and any video that comes in - no matter it's width, height or aspect ratio - should also be centered.


      By default, if I drag the FLVPlayback component onto the stage and center it, all videos are still loaded to the components top left hand corner and the video spreads to the right and down - leaving white sspace top and left. What I want is for the video to load in the center of the stage AND in the center of the component, therefore leaving equal amounts of white space top, left, right and down.


      Is this possible in AS2 (I need to use AS2 for this exercise) if so, does anyone know how to do it?







      Message was edited by: tjay99 I should have also said the swf is being loaded into an AIR full screen app, therefore I am not using HTML to align anything once it's been published. The AIR app just loads in the swf and plays it.

        • 1. Re: Aligning video to stage as2

          Flash always Load stuff on registration point of mc.


          So either you change it to a top/left position that ends up centering the content (wich won't work in case u load dif. sized videos).


          What I do when i want the same result as you is to get the width/height of the loaded clip, and after that reposition it like;


          tempImage._x = - tempImage._width/2; ///centers horizontally


          In order to perform this u have to use the movieClipLoader class (if you are not using it), so that u can set this reposition tasks onLoadInit, otherwhise flash won't be able to get the loaded clip's width/height.

          • 2. Re: Aligning video to stage as2

            You can use metadata loaded event of the FLVPlayback.


            var listenerObject:Object = new Object(); listenerObject.progress = function(eventObject:Object):Void { if(my_FLVPlybk.metadataLoaded){ trace("Height is " + my_FLVPlybk.metadata.height); trace("Width is " + my_FLVPlybk.metadata.width); trace("Duration is " + my_FLVPlybk.metadata.duration + " seconds"); } }; my_FLVPlybk.addEventListener("progress", listenerObject); my_FLVPlybk.contentPath = "http://www.helpexamples.com/flash/video/water.flv";


            In this you can use width height of the video and then realing it.

            • 3. Re: Aligning video to stage as2
              tjay99 Level 1

              Thanks guys for your help. I did the demo fine and understand what is going on there. By when I tried to change the _height and _width of either the FLVPlayback component or the MC which is surrounding it it didn't change. Now I'm out of my depth :-(


              I come across this code:


              var myMCL:MovieClipLoader = new MovieClipLoader();
              var ml:Object = new Object();
              ml.onLoadInit = function(my_VidHold:MovieClip) {
                  my_VidHold._x = 50;
                  my_VidHold._y = 50;

              myMCL.loadClip("pic1.jpg", container_mc);


              which does what I think was suggested, but I don't know how to incorporate that into the metadata code that was also provided?


              By the sounds of things, I need to load a movieClip into a movieClip, as everything needs to be eventually centered onto the page as well.


              Any further guidance would be greatly appreciated.




              • 4. Re: Aligning video to stage as2
                tjay99 Level 1

                I found this code too:



                test.source = "video.flv";
                stage.addEventListener(Event.RESIZE, resizeDisplay);
                stage.scaleMode = StageScaleMode.NO_SCALE;
                stage.align = StageAlign.TOP_LEFT;
                function resizeDisplay(event:Event = null):void {
                test.x = (stage.stageWidth >> 1) - (test.width >> 1);
                test.y = (stage.stageHeight >> 1) - (test.height >> 1);



                which only works under AS3, but does part of want I want.


                The error I get is:


                "The class or interface 'Event' could not be loaded."


                Is there a way to do that under AS2? Then once I get that working, I'll try to then tackle aligning of the video to the FLYPlayback.