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.

import mx.video.FLVPlayback;
import mx.video.VideoPlayer;

class CenteredFLVPlayback extends FLVPlayback
{
    private var m_sizedW:Number;
    private var m_sizedH:Number;
   
    public function CenteredFLVPlayback()
    {
        super();
        this.m_sizedW = this.width;
        this.m_sizedH = this.height;
    }
   
   
    public function setSize(p_w:Number, p_h:Number):Void
    {
        super.setSize(p_w, p_h)
       
        this.m_sizedW = p_w;
        this.m_sizedH = p_h;
        // align content
        var i:Number = _vp.length;
        while (i--)
        {
            if (_vp[i] != undefined)
            {
                this.alignPlayer(_vp[i], p_w, p_h)
            }
        }
    }
   
    private function alignPlayer(p_vid:VideoPlayer, p_w:Number, p_h:Number):Void
    {
        p_vid.x = (p_w/2) - (p_vid.width/2);
        p_vid.y = (p_h/2) - (p_vid.height/2);   
    }
   
   
    private function showFirstStream():Void
    {
        super.showFirstStream();
        this.alignPlayer(VideoPlayer(this._vp[this._visibleVP]), this.m_sizedW, this.m_sizedH);
    }
}

Leave a Reply