SWF-PHP
What is SWF-PHP?
SWF-PHP is a PHP 5 class that produces standards-compliant code for embedding SWF files on the web.
If you've worked in Flash AS3 development, you'll know that IDEs generate some horrific HTML/javascript for embedding your SWF file on the web. Most developers want their HTML to validate perfectly AND have a standardized way of integrating SWFs into web applications without having to alter their design patterns or architecture. SWF-PHP provides that functionality.
What does it do?
SWF-PHP allows developers to do the following:
- Create fully-compatible, standards-compliant HTML for embedding SWF objects in web pages
- Easily integrate SWFs into frameworks and object-oriented design patterns
- Easily control the settings of individual SWFs, including dimensions, transparency, FlashVars, menu settings and more without having to fiddle with the code or javascript every time you need to make a change
- Keep core javascript required to run the SWF separate from the javascript in your application (extremely useful if you're dealing with legacy AS2 or AS3 applications that use fscommand)
How does it work?
Unfortunately we still need some javascript because of ActiveX and security issues, but its quite succinct. All you need to do is include the javascript library in your header (or in the body somewhere before any calls are made):
<script type="text/javascript" src="swf-php.js"></script>
Then, in your PHP file, you simply include the class library:
<?php
require_once('SWF.php');
?>
You're now ready to instantiate any number of SWFs. This can be done in as little as two lines of code:
<?php
$swf = new SWF("example.swf");
echo $swf->html ;
?>
That's all! The standards-compliant output looks like this:
<div id="swfphp0_container" style="display:block;width:100%;height:100%;">
<script type="text/javascript">
<!--
SWF_RunStandardsContent(
{
'type':'application/x-shockwave-flash',
'data':'example.swf',
'width':'100%',
'height':'100%',
'id':'swfphp0',
'name':'swfphp0'
},
{
'allowScriptAccess':'sameDomain',
'allowFullScreen':'true',
'swliveconnect':'false',
'FlashVars':'',
'menu':'false',
'quality':'high',
'bgcolor':'#ffffff',
'wmode':'opaque',
'scale':'exactfit',
'movie':'example.swf'
}
);
// -->
</script>
<noscript>
<div style="width:100%;height:100%;">
<object type="application/x-shockwave-flash" data="example.swf" width="100%" height="100%" id="swfphp0" name="swfphp0" style="display:block;">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="true" />
<param name="swliveconnect" value="false" />
<param name="FlashVars" value="" />
<param name="menu" value="false" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="wmode" value="opaque" />
<param name="scale" value="exactfit" />
<param name="movie" value="example.swf" />
</object>
</div>
</noscript>
</div>
And the resulting SWF: