Thursday, January 17, 2013

Embed Flash with PHP.

Its been a while. I figured I should put something up. Here is a class I wrote to put Flash on a page with PHP. Enjoy.


<?php
/**
 * Description of flash
 * @author Joseph Tveter
 *
 * This will build the object to embed a swf in.
 */
include_once 'view/html/HTML.php';
class flash {
    private $embedAttrs = array(
        "src"               => "flash_obj.swf",
        "quality"           => "high",
        "bgcolor"           => "#ffffff",
        "width"             => "1024",
        "height"            => "600",
        "name"              => "flash_obj",
        "align"             => "middle",
        "allowScriptAccess" => "sameDomain",
        "allowFullScreen"   => "false",
        "type"              => "application/x-shockwave-flash",
        "pluginspage"       => "http://www.adobe.com/go/getflashplayer",
        "vspace"            => "",
        "hspace"            => "",
        "class"             => "",
        "title"             => "",
        "accesskey"         => "",
        "tabindex"          => "",
        "flashvars"         => "",
    );
    private $params = array(
        "allowScriptAccess" => "sameDomain",
        "allowFullScreen"   => "false",
        "movie"             => "lobby.swf",
        "quality"           => "high",
        "bgcolor"           => "#ffffff",
    );
   
    private $objAttrs = array(
        "classid"            => "clsid:d27cdb6e-ae6d-11cf-96b8-444553540042",
        "codebase"           => "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0",
        "width"              => "1024",
        "height"             => "600",
        "id"                 => "flash_obj",
        "align"              => "middle",
        "onafterupdate"      => "",
        "onbeforeupdate"     => "",
        "onblur"             => "",
        "oncellchange"       => "",
        "onclick"            => "",
        "ondblclick"         => "",
        "ondrag"             => "",
        "ondragend"          => "",
        "ondragenter"        => "",
        "ondragleave"        => "",
        "ondragover"         => "",
        "ondrop"             => "",
        "onfinish"           => "",
        "onfocus"            => "",
        "onhelp"             => "",
        "onmousedown"        => "",
        "onmouseup"          => "",
        "onmouseover"        => "",
        "onmousemove"        => "",
        "onmouseout"         => "",
        "onkeypress"         => "",
        "onkeydown"          => "",
        "onkeyup"            => "",
        "onload"             => "",
        "onlosecapture"      => "",
        "onpropertychange"   => "",
        "onreadystatechange" => "",
        "onrowsdelete"       => "",
        "onrowenter"         => "",
        "onrowexit"          => "",
        "onrowsinserted"     => "",
        "onstart"            => "",
        "onscroll"           => "",
        "onbeforeeditfocus"  => "",
        "onactivate"         => "",
        "onbeforedeactivate" => "",
        "ondeactivate"       => "",
        "type"               => "",
        "vspace"             => "",
        "hspace"             => "",
        "class"              => "",
        "title"              => "",
        "accesskey"          => "",
        "name"               => "",
        "tabindex"           => "",
        "devicefont"         => "",
        "flashvars"          => "",
        );
   
    public function __construct($args) {
        foreach($args as $k => $v){
            foreach($this->embedAttrs as $key => $val){
               if($k == $key){
                   $this->embedAttrs[$k] = $v;
               }
            }
            foreach($this->params as $key => $val){
                if($k == $key){
                    $this->params[$k] = $v;
                }
            }
            foreach($this->objAttrs as $key => $val){
                if($k == $key){
                    $this->objAttrs[$k] = $v;
                }
            }
        }
    }
   
    public function draw(){
        $html = new HTML("object");
        foreach($this->objAttrs as $k => $v){
            if($v != ""){
                $html->addValue($k, $v);
            }
        }
       
        foreach($this->params as $k => $v){
            if($v != ""){
                $pram = new HTML("param");
                $pram->addValue("name", $k);
                $pram->addValue("value", $v);
                $html->addChild($pram);
            }
        }
        $embed = new html("embed");
        foreach($this->embedAttrs as $k => $v){
            if($v != ""){
                $embed->addValue($k, $v);
            }
        }
        $html->addChild($embed);
        return $html;
    }
}

?>