Tutorial: Setting up Wordpress to communicate with Flash via XML
by adam
This following bit of code should get you up and running with a simple way of sharing data from your wordpress blog with a flash object. Creating the XML file is a bit of a hastle, since you can’t output XML directly from a wordpress template file to flash. Instead you have to use php’s fopen function to save your xml file to be accessed separately through your flash object.
The PHP
<?php // set headers header('Content-Type: text/xml'); header('Cache-Control: no-store'); // get database results to output xml $query = "SELECT content FROM wp_table ORDER BY id DESC LIMIT 10"; $terms = $wpdb->get_results($query, OBJECT); $xml .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $xml .= "<data>Your Data Goes Here</data>"; // save your xml file in your theme directory $path = 'wp-content/themes/themename/output.xml'; $file= fopen("$path", "w"); fwrite($file, $xml); fclose($file); ?>
The HTML & Javascript
<div align="top" style="margin-left:-10px;"id="flashcontent"> <a href="http://www.adobe.com/shockwave/download/triggerpages_mmcom/flash.html"><img src="noFlash.jpg" width="600" height="270" border="0" alt="Flash Not Detected" /></a> </div> <script type="text/javascript"> // <![CDATA[ var so = new SWFObject('<?php bloginfo ( 'template_directory' );?>/flashobject.swf', 'website', '600', '270', '9'); so.useExpressInstall('<?php bloginfo ( 'template_directory' );?>/expressinstall.swf'); so.addParam('menu', 'false'); so.addParam('wmode', 'transparent'); so.addVariable("xmlVar", '<?php bloginfo ( 'template_directory' );?>/output.xml'); so.write('flashcontent'); // ]]> </script>
This is exactly what I’m looking for, but I don’t get how it works ?
Please explain a little bit more …
Best Regards,
Ced.
Hi ced, which part are you confused by? The code is fairly straight-forward, you are simply formatting your data from wordpress in xml so that it may be passed into flash.
I highly enjoyed reading this blogpost, keep up posting such interesting stuff!!