Location: PHPKode > scripts > Flash External Interface > flash-external-interface/Flash_ExternalInterface.php
<?php

class Flash_ExternalInterface {

	function displayJS($object_tags, $function_source) {
	
		header("Content-type: application/x-javascript");
		header("Expires: Thu, 01 Dec 1994 16:00:00 GMT");
		header("Last-Modified: ". gmdate("D, d M Y H:i:s"). " GMT");
		header("Cache-Control: no-cache, must-revalidate");
		header("Cache-Control: post-check=0, pre-check=0", false);
		header("Pragma: no-cache");
		
print "<!--

document.write('$object_tags');
$function_source

//-->";
		
	}

}

class Flash_Object_tags {

	function getTags($params) {
	
		$url = $params["url"];
		$width = $params["width"];
		$height = $params["height"];
		$wmode = $params["wmode"];
		$quality = $params["quality"];
		$allowScriptAccess = $params["allowScriptAccess"];
		$bgcolor = $params["bgcolor"];
		$align = $params["align"];
		$id = "external". md5(uniqid(rand(),1));
		
		$setting_propaties = array(
							
								"wmode" => $wmode, 
								"quality" => $quality, 
								"allowScriptAccess" => $allowScriptAccess, 
								"bgcolor" => $bgcolor
								
							);
		$parma_tag = $this->createParamTag($setting_propaties);
		
		$setting_propaties["align"] = $align;
		$embed_propaties = $this->createEmbedPropaties($setting_propaties);
		
		$return = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" width="'. $width .'" height="'. $height .'" id="'. $id .'"'. $this->createObjectPropaties($align) .'>
					<param name="movie" value="'. $url .'"></param>
					'. $parma_tag .'
					<embed src="'. $url .'"  width="'. $width .'" height="'. $height .'" name=""'. $embed_propaties .' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
					</object>';
		
		return str_replace(array("\n", "\r", "\t"), "", $return);
		
	}
	
	function createObjectPropaties($align) {
	
		$return = ($align == "") ? "" : ' align="'. $align .'"';
	
	}
	
	function createParamTag($setting_propaties) {
	
		$return = "";
	
		foreach($setting_propaties as $key => $value) {
		
			if($value != "") {
			
				$return .= '<param name="'. $key .'" value="'. $value .'"></param>';
			
			}
		
		}
	
		return $return;
	
	}
	
	function createEmbedPropaties($setting_propaties) {
		
		$return = " ";
		
		foreach($setting_propaties as $key => $value) {
		
			if($value != "") {
			
				$return .= $key .'="'. $value .'" ';
			
			}
		
		}
		
		return $return;
		
	}

}

class Flash_function_source {
	
	function getSource($function_name, $setDatas, $encoding="") {
		
		$source = "";
		$var_name = "var". md5(uniqid(rand(),1));
		
		if(is_array($setDatas)) {
		
			$var_count = 0;
		
			foreach($setDatas as $key => $value) {
				
				if($encoding != "") {
				
					$value = mb_convert_encoding($value, "UTF-8", $encoding);
				
				}
				
				if(!is_numeric($key)) { 
				
					$key = "'". $key ."'";
					
				}
				
				$source .= "\t". $var_name ."[". $key ."] = decodeURIComponent('". rawurlencode($value) ."');\n";
				$var_count++;
				
			}
			
			$source = "\tvar ". $var_name ." = new Array(". $var_count .");\n". $source ."\n";
			
		}
		
		return "function ". $function_name ."()\n{\n". $source ."\treturn ". $var_name .";\n}";
	
	}

}

/*** Sample Source

	require("Flash_ExternalInterface.php");
	
	$params = array(
	
		"url" => "http://example.com/example.swf", 
		"align" => "middle", 
		"width" => 160, 
		"height" => 115,
		"wmode" => "",
		"quality" => "high",
		"allowScriptAccess" => "always",
		"bgcolor" => "#FFFFFF"
	
	);
	
	$fo =  new Flash_Object_tags();
	$object_tags = $fo->getTags($params);
	
	$setDatas = array(
	
		"test1" => "テスト1", 
		"test2" => "テスト2", 
		"test3" => "テスト3", 
		"test4" => "テスト4", 
		"test5" => "テスト5"
	
	);
	
	$function_source = Flash_function_source::getSource("functionName", $setDatas, "UTF-8");
	Flash_ExternalInterface::displayJS($object_tags, $function_source);

***/

?>
Return current item: Flash External Interface