Tutorial: Setting up Wordpress to communicate with Flash via XML
by adam on October 12, 2009
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>

Flickr
Quora
5 comments
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.
by ced on October 30, 2009 at 12:54 pm. #
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.
by Adam Breckler on October 31, 2009 at 11:23 am. #
I highly enjoyed reading this blogpost, keep up posting such interesting stuff!!
by sleelfiny on December 11, 2009 at 3:52 pm. #
Hi Adam just wondering would this code allow me to imort a flash file into wordpress and have that flash file read XML for instance a flash carousel.
Is so could you please explain the file structure where would I put the above code.
I am trying to insert a flash carousel with XML file into the header part of a wordpress blogg please could you help.
Kind regards JD
by JD on August 20, 2011 at 3:18 pm. #
This piece of code was heaven sent! Thanks for the post Adam!
by Arion Diaz on January 17, 2012 at 3:36 pm. #