Aligning Videos in FLVPlayback (AS2 version)


Though we don't use the FLVPlayback, someone asked me how to align video in the AS2 version. If you want to do alignment, here's a simple hack done by extending the FLVPlayback class which centers the videos.

Actionscript:
  1. import mx.video.FLVPlayback;
  2. import mx.video.VideoPlayer;
  3.  
  4. class CenteredFLVPlayback extends FLVPlayback
  5. {
  6.     private var m_sizedW:Number;
  7.     private var m_sizedH:Number;
  8.    
  9.     public function CenteredFLVPlayback()
  10.     {
  11.         super();
  12.         this.m_sizedW = this.width;
  13.         this.m_sizedH = this.height;
  14.     }
  15.    
  16.    
  17.     public function setSize(p_w:Number, p_h:Number):Void
  18.     {
  19.         super.setSize(p_w, p_h)
  20.        
  21.         this.m_sizedW = p_w;
  22.         this.m_sizedH = p_h;
  23.         // align content
  24.         var i:Number = _vp.length;
  25.         while (i--)
  26.         {
  27.             if (_vp[i] != undefined)
  28.             {
  29.                 this.alignPlayer(_vp[i], p_w, p_h)
  30.             }
  31.         }
  32.     }
  33.    
  34.     private function alignPlayer(p_vid:VideoPlayer, p_w:Number, p_h:Number):Void
  35.     {
  36.         p_vid.x = (p_w/2) - (p_vid.width/2);
  37.         p_vid.y = (p_h/2) - (p_vid.height/2);   
  38.     }
  39.    
  40.    
  41.     private function showFirstStream():Void
  42.     {
  43.         super.showFirstStream();
  44.         this.alignPlayer(VideoPlayer(this._vp[this._visibleVP]), this.m_sizedW, this.m_sizedH);
  45.     }
  46. }

  1. No comments yet.
(will not be published)