How to connect WordPress and Flash – part #2

Finally, part 2 of this tutorial is here. Part 1 can be seen HERE. There you can find out how to prepare and format data for Flash and now we are about to do something with it. I’ve made a package of all required files for download so you can see what else will be used. Please download ZIP, unpack and open WP_flash.fla. Code is well commented and I am not about to explain how and why. This is just an example of my own implementation, you may develop your own and display data differently in Flash. My goal was to demonstrate WP – Flash data exchange on the simplest possible way.

How to use it?

Just for demo purpose upload all the files (and ’script’ folder as well!) to the root of your theme, it doesn’t matter which one. Now you need to call ‘WP_flash_holder.php’ in Browser but full path to this file must be used because we are currently out of WP ‘native environment’:
http://yourdomain.com/wp-content/themes/your_theme_name/WP_flash_holder.php.
For a case you are about to include WP_flash.swf in any existing template file of your theme (for example sidebar.php), things will work normally.

NOTE:

Open WP_flash_holder.php and change path to match your domain and theme name otherwise it’ll not work. For example the line reading:


<script src="http://your_domain.com/wp-content/themes/your_theme_name/script/swfobject.js" type="text/javascript"></script>

As well as:


var so = new SWFObject( "http://your_domain.com/wp-content/themes/your_theme_name/WP_flash.swf", "wpflash", "550", "400", "8" );

…must be replaced with your own data!

Files in package…

  • slidestyle.css
    Flash Player supports a subset of properties in the original CSS1 specification only so basic text formatting can be done here. Not much but enough for this tutorial.
  • WP_flash_holder.php
    This file is here just to properly include/embed Flash file into HTML page. In source code you can read how to include Flash in native WordPress environment (for example sidebar.php).
  • script > swfobject.js
    As already mentioned, swf must be properly embed so this is nothing but a piece of javascript code required to avoid page errors and Browser warnings.
  • WP_flash.fla and WP_flash.swf
    Source and rendered file used for demonstration purpose.

It’s good to know

I guess some of you already plan to make a first Flash theme so it’s good to know that each and every WP theme must fulfill minimum requirements. Theme folder MUST contain the following files: index.php, style.css and functions.php (screenshot.png). In that case you can keep all of your Flash styles in style.css and embed Flash into index.php. Remember, it’s a long way to develop Flash theme and this tutorial is just a little tiny foot step on the long path up to the hill. Enjoy!

Share with others...

deliciousdiggreddittechnoratifacebooktwittergoogleyahoowikioblinklistsimpyspurl
Comments (10)

Track comments via RSS 2.0 feed. Feel free to post the comment, or trackback from your web site.

  • jlo on Jul 9, 2009

    is there and easy way to specify which category the php file pulls from in word press? I have tried looking up the category ID but that seems to not work or if i specify the direct name of the category

  • Feeleep on Jul 9, 2009

    You must definitely know category ID if you are about to pull posts from certain category. So the query_posts() call should read something like

    
    query_posts( 'showposts=' . $num_of_posts_to_display . '&post_type=post&post_status=publish&order=DESC&cat=YOUR_CAT_ID' );
    
    

    Dont forget to replace YOUR_CAT_ID with numeric value! For more information please refer to http://codex.wordpress.org/Template_Tags/query_posts. Hopefully it helps!

  • André Beltrame on Jul 20, 2009

    Great tutorial…
    im waiting now the next.. wordpress is a best cms for me… this integration is perfect… many thanks for it!

  • chris on Mar 9, 2010

    Hi,
    I want to locate my swf file in the root of my wordpress blog not in the template dir.

    But for some reason, i keep getting errors in flash when i try to call the “slide_serve.php” from anywhere outside the template dir. Does the swf have to live in the same dir as the slide_serve.php file to get access?

    Any help would be much appreciated!

    Thanks,
    Chris

  • Feeleep on Mar 10, 2010

    Yeap, ’slide_serve.php’ by default MUST share location with Flash file (SWF) which checks its own path in file system on server – according to which PHP file is found.

    However, if you take a look at FLA, line number 53 which reads:

    
    extXML.load( myloc + "/slide_serve.php" );
    
    

    …you can easily change location/path to ’slide_serve.php’ manually.
    Hopefully it helps!

  • chris on Mar 11, 2010

    Thanks for your help,
    I managed to work it out.

    Lastly, im using as3 and when i try to pull in the xml it crashes because it’s not properly formatted. I don’t know php very much, not at all actually but I managed to format it the way i wanted it, except, here’s the problem with the formatting:

    in the slide_serve.php when calling “require_once( ‘../../../wp-config.php’ );” it automatically spits out “http://www.mydomain.com”*amount of entries. For example, if i have 5posts in my blog it will spit out “http://www.mydomain.comhttp://www.mydomain.comhttp://www.mydomain.comhttp://www.mydomain.comhttp://www.mydomain.com”.

    So my question is, since i have no idea about anything php related, is there any way to get rid of this? I simply want the xml echoed out.

    Hoping there is a quick solution :)

    Thanks for any help in this,
    Chris

  • Feeleep on Mar 11, 2010

    Honestly spoken I didn’t make any tests to see whether the script works for AS3 but I guess it doesn’t due to a little bit different syntax. Anyway, I would love to see how your ’slide_serve.php’ looks like coz I think there must be something wrong.
    Chris, you can drop me a message, zip up ’slide_serve.php’ and I let you know my opinion.

  • chris on Mar 12, 2010

    Ok thanks so much, i sent you a message through your contact page (probably same mail as this :)).

    C

  • benjamin on Mar 12, 2010

    Hello, I have an as3 version of it..
    you didn’t know because my comments where stuck in your trash because of bad web adress i wrote (.xom instead of .com)

    I’ve ported this to as3 few times ago.

    I can send it to you

  • Feeleep on Mar 12, 2010

    Benjamin, will you be able to put AS3 version on your own server so other people can download it too? Thanks!

Leave a Comment

Latest comment by Feeleep

Benjamin, will you be able to put AS3 version on your own server so other people can download it too? Thanks!

Search

Advertisement

GraphicRiver ThemeForest