Interfacing Flash with Drupal

Please note that this article is rather dated. Although, the techniques mentioned in this article are still valid and are the "easiest way", it is not considered the right way to perform Drupal and Flash Interaction. The right way is to use the Services Module. I will be updating this tutorial very soon with the proper method for Flash to Drupal interaction, but in the meantime, keep in mind that this article will be changing soon.

Introduction

Like most people out there, I absolutely love Flash. More specifically, I love Flash websites...and you can always tell if a website uses it or not. Believe me...it makes a huge difference in the overall appeal of your website. However, what I have discovered the hard way is that trying to interface a Flash applet with your Drupal website is somewhat painful. And when I say interface, I am talking about the exchange of data... actually having your Flash applet extract information from your Drupal database. "Whaaaaaaa???" you say? Yes!... you can actually do this (I just had to do this in my latest version of FlashVideo)! And guess what? I will show you how...

Oh, on a side note, good luck trying to find this information anywhere else on the Internet. I tried but didn't succeed. So instead of just giving up, I actually brainstormed on a method of actually doing this. So, in this tutorial, I will explain to you the easiest way to happily marry Flash applets with a Drupal website. So, let us begin.



Understand how Flash extracts data

Flash receives outside data through the use of parameters passed to the Flash applet. There are two ways to pass parameters to your Flash applet. You can either use the $_GET method where you just specify parameters as you would in a URL like flashapplet.swf?param1=2¶m2=3, or by just using the parameter called FlashVars. FlashVars works very similar to that of the $_GET method and is actually the preferred method for sending data to your flash application. You do this by specifying a new parameter in the object code of your Flash object. It should look like the following.

<param name="FlashVars" value="param1=a&param2=b&param3=c" />

Note that each parameter passed using FlashVars are separated by an "&". Flash will then parse each one of these parameters and actually create a variable within the ActionScript so that you can use it willingly. However, using this method, you must specify every single parameter separately and within the actual object code. Do you see the problem? What if you wanted to pass a whole lot of data to the Flash applet? Well, in response to this, Flash has also added the ability to extract parameter information from external files. You actually open the file and extract the file information within the ActionScript of the Flash applet (which is beyond the scope of this tutorial), but a person could easily specify WHICH file to open by using this FlashVars parameter like the following.

<param name="FlashVars" value="file=external_file.txt" />

Now this file can be in the form of an XML file (if you wish to do XML parsing), a text file, or even better a URL... Hmmmmmm... Now were onto something. If I can specify a URL, then that would mean that I could also specify a PHP file, and then in the PHP file just echo any of the parameters to the Flash applet (XML format or whatever else)!! Now, that's cool!!!... unless your using Drupal.

The problems with Drupal

Drupal, if you haven't figured this out already, has a ninja death grip on all database extraction. What I basically mean by this, is the only way to truly extract any database information from Drupal is do so through the Menu / Path system of Drupal. This is just crappy for me, because this means that I can't specify a file that just gives me the raw data and nothing else!!! This is a great thing for web security, but painful if you wish to have a Flash applet extract information from your Drupal database. This is what took me forever to figure out how to bypass. I tried everything from creating a separate template file... actually creating a file and using external database modules...you name it. I just couldn't figure out how to get all the raw data without Drupal adding all that template HTML crap along with it. Well, after much learning and studying of the Drupal system, I finally figured out the easiest way to do this. I basically asked myself "When I go to any Drupal URL, where is it actually going?". And the answer was simple... index.php. All the magic of Drupal happens in this extremely small file. I know it is hard to believe, but it does. When you go to ANY url in the Drupal system, you are actually going to www.travistidwell.com/index.php and then anything else is just passed as an argument to this file. This is actually brilliant on Drupal's part. So, how do you extract information from your Drupal database with a PHP file... well, create your own version of the index.php file, thats how! For this tutorial, we will call it flash_interface.php.

Create your very own flash_interface.php file

The first thing that we need to do is create a new file called flash_interface.php and place that file in the root directory of Drupal (right next to the index.php file). The next thing that I am going to ask you to do is actually open up the index.php file. You can learn so much from these 40 lines of code. If you actually study the index.php file, you will notice two extremely important lines. The following code will be your template for creating an interface file.

<?php
   
require_once './includes/bootstrap.inc';      
   
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
?>

These two little lines are all that it takes to basically "boot" Drupal. Think of it as a Windows operating system. The first thing that happens is your system boots up and loads windows. What does it do after that? Well, it starts loading applications. Well, in your flash_interface.php file, we want to boot Drupal, but don't want to start all the Menu / Path application stuff... so, we just won't include it. So in your flash_interface.php file, all you need to do is place those two lines at the very top of the file, and then you will have complete access to all the Drupal stuff!! One big thing is the database functions such as db_query will work as they normally would in a Drupal page or custom module. So, after those two lines you can put whatever you want, and echo whatever you want! What this means is that you can extract Drupal database information, and then just echo that information to your Flash applet! Here is an example...

<?php
  
/*
    *   Let us suppose that we want to create a Flash widget
    *   that shows how many nodes are in the system.
    *   This Flash applet will be simple in that all it expects
    *   as a parameter is the node_count variable.
    */

  
require_once './includes/bootstrap.inc';   
  
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);  // "boot" Drupal 

   // Here we extract the information from the database and echo
   // that information in a Flash readable format.
  
$count = db_result(db_query("SELECT count(*) FROM {node}"));     
   echo
'node_count='.$count;                                 
?>
flash_interface.php

Pass your flash_interface.php file to the Flash applet

So, how does this all tie in with your Flash applet? Well, remember the FlashVars parameter? All you need to do is just specify the following parameter in your Flash object code.

<param name="FlashVars" value="file=http://www.travistidwell.com/flash_interface.php" />

What you can then do in your ActionScript for you Flash application is just open this as you would a normal file. To Flash, this would be the same as if you just opened a text file with all this information in it. However, since it is a PHP file, you are completely at liberty to make it DYNAMIC data using the Drupal Database. Now that's cool!!!

Take it one step further

Ok, now lets suppose that we wish to make a Drupal page that has a Flash widget right smack in the middle. All this widget wishes to do is show you the node information of the current page... Using this method, you could actually do this! Here's how... First, you will need to create a new page. In that page you will need to place the object code for your Flash widget. It should look simlar to the following.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  width="320" height="240"        
  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
  <param name="movie" value="http://www.travistidwell.com/files/MyFlashWidget.swf" />
  <param name="wmode" value="transparent" />
  <param name="FlashVars"
    value="file=http://www.travistidwell.com/flash_interface.php?nid=<?php print $node->nid ?>" />
  <param name="quality" value="high" />
  <embed allowScriptAccess="always" src="http://www.travistidwell.com/files/MyFlashWidget.swf"
    width="320" height="240" border="0" type="application/x-shockwave-flash" 
    pluginspage="http://www.macromedia.com/go/getflashplayer"
    wmode="transparent" quality="high" 
    flashvars="file=http://www.travistidwell.com/flash_interface.php?nid=<?php print $node->nid ?>" />
</object>
Don't forget to change the Input Format to PHP Code!

Do you see what I did? I basically am now passing a $_GET variable to my PHP file that has the current node ID. With this information, I can construct my flash_interface.php file to look like the following.

<?php
  
require_once './includes/bootstrap.inc';
  
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);  // "boot" Drupal

   // Here we will extract the node information from the Drupal database, and then echo that information
   // in a Flash readable format.
  
if(isset($_GET['nid']) && is_numeric($_GET['nid'])) {
     
$node = db_fetch_object(db_query("SELECT * FROM {node} WHERE nid=%d", $_GET['nid']));  
     
$params = 'nid='.$node->nid;                                                            
     
$params .= '&title='.$node->title;    
      echo
$params;                        
   }
?>
flash_interface.php

What will happen now, is that the Flash widget in the middle of my node will now have information about that node!!! Now, how freakin cool is that!!!

Hope you enjoyed this tutorial...

well worth the read.I found

well worth the read.I found it very informative as I have been researching a lot lately on practical matters such as you talk about...
Scoruri Live
Biletul Zilei
Bonus Bet365
Bonus Gamebookers
Bonus Unibet
Bonus Partybets
Bonus Doxxbet
Bonus William Hill

links of london

If you want to have a florid links of london Horseshoe charm,Links of london online store, which provides links london Horseshoe charm which designs and styles are all from Jewelry, may be your choice.Wait for your order.now links of london sale lets suppose that we wish to make a Drupal links of london Earringslinks of londonsweetie bracelets page that has a Flash widget right smack in the middle links of london friendship All this widget wishes to do is show you the node information of the current page... Using this method, you could actually do this! Here's how... First, you will need to create a new page.links of london Silver Chain In that page you will need to place the object code for your Flash widget. It should look simlar to the following.

links of london

A links of london Lucky Catch Shell Charm is not only increasing your charm, but also bringing you good luck, it is said that shooting two birds is with one stone at llinks of london store.Lucky links london give luck to you.now lets suppose that we wish to make a Drupal page that has a Flash widget right smack in the middle.cheap links of london All this widget wishes to wholesale Links of London do is show you the node links of london 2010 NEW ARRIVALS information of the current page... Using this method, you could actually do this! Here's how... First, you will need to links of london wholesale
create a new page. In Links of London jewellery
links of london Friendship Bracelets
that page you will need to place the object code for your Flash widget. It should look simlar to the following.

Hey, it seems that you are

Hey, it seems that you are good at internet marketing and Drupal manufacture. You can join Freelancer.com to get more projects regarding both subject. Use this code BUILDIT4ME to get more advantages from the site. Good luck. Cleansing diet

What will happen now, is

What will happen now, is that the Flash widget in the middle of my node will now have information about that node!!! Now, how freakin cool is that!!!
Tower defense

I've been trying for ages

I've been trying for ages now to put some flash with Drupal, but I don't think I can do it. This post really help me out. Thanks buddy. I'll let you know my progress later. Thanks.

Tower defense

Once we dreamt that we were

Once we dreamt that we were strangers. We wake up to find that we were dear to each other.  lol! cheers!!

dog obedience training

Morality is not really the

Morality is not really the doctrine of how to make ourselves happy but of how we are to be worthy of happiness.

web templates

I will look into being more

I will look into being more selective with my commands to the bootstrap routine. I guess it really depends on your requirements.

cheap reseller hosting

Foot smell, loss of

Foot smell, loss of confidence, mainly cause people many psychological problems is one of the reasons. Produced as a mixture of private and public have been available to us through the bad foot odor Fx7 date is mixed. Single use is effective in 120 days. Moreover, the pores and sweat without cutting without clicking ..

tower defense games

Help

The tutorial is pretty good, but you need to be more specific about it please !!??

ECN Broker | Metatrader 4 Trading | Forex Trading Platforms

Do you see what I did? I

Do you see what I did? I basically am now passing a $_GET variable to my PHP file that has the current node ID. With this information, I can construct my flash_interface.php file to look like the following.
abercrombieandfitch
fitch clothing
abercrombie and fitch
abercrombieandfitch sale
abercrombie and fitch uk
abercrombie and fitch usa
links of london
sweetie bracelet
charm bracelets
charm bracelet
bracelet charms
silver charms
silver bracelets
links of london bracelets
links of london charms

HMM.

thanx alot this will hlp me out alot..:D

_______________

Brabantia Bins

i'm coming!!! tiffany

i'm coming!!!

tiffany jewelry
Choose, buy and shop for on sale tiffany jewelry including Tiffany & Co Silver Necklace, Pendants, Bangles, Bracelets, Earrings, Rings and Accessories.
tiffany co
Tiffany Jewellery offering bangle Jewellery, bracelet jewelry, eardrop jewelry, necklace jewelry, ring jewelry, finger ring jewelry and earring jewelry
tiffany
tiffany and co
links of london
links london
Tiffany Style Silver Jewelry: Rings, Earrings, Necklaces, Bracelets and more Tiffany Jewellery at low prices.

I've been trying for ages

I've been trying for ages now to put some flash with Drupal, but I don't think I can do it. This post really help me out. Thanks buddy. I'll let you know my progress later. Thanks.
office chairs

I will look into being more

I will look into being more selective with my commands to the bootstrap routine. I guess it really depends on your requirements. cheers!!!

korea fashion

Awesome stuff here thanks

Awesome stuff here thanks man i needed this!
e cigarette, e cigarettes

Really good tips!

Really good tips. It gave me all basic knowledge for using Flash with Drupal. I never thought it's so simple.
Sincerely, Tommy Fine Jewelry

uggs

ugg boots sale -The best Christmas Persents for Lover & Family
Christmas is coming,it's great time to shop Genuine UGG Boots as Christmas gifts to keep your lover & family warm and cozy.Love UGGs,Love UGG Boots UK
Ugg london sale is fashionable & warm and comfortable ugg boots London. Welcome to visit the uggoflondon.co.uk, you may will have unexpected surprises!
bailey button ugg boots
tall ugg boots,
cardy ugg boots,
UGG Sundance Boots.

Hey, thanks man, I never

Hey, thanks man, I never thought that Drupal can be combined with flash. Never try it either, though. But thanks, I'm going to try it now. It will be an advantage in my SEO campaign.
poker omaha

thank you for this awesome

thank you for this awesome post pal, cheers. . .

Carpet Cleaners Machine

btw, if you want to see more

btw, if you want to see more tutorial for Drupal, you can see their official website. They have a lot of tutorial and some videos too. Good luck.
madrid centro

Rado watch for sale

Tiffany Rings

Rado watches

it has got a great

it has got a great interface, any begginer can easily find a way . .

cheap holiday

i think there are some

i think there are some problems with the codes, not all of them seem to work properly. .

Oil Paintings

i think there are some

i think there are some problems with the codes, not all of them seem to work properly. .

Christian Louboutin Shoes

thanks all the time, These Christian louboutin shoes was one of fashion’s best-

kept secrets:means  Christian shoes has attracted a growing clientele for whom the fact that he is not a household name is all part of the appeal. “The minute we receive a delivery of his
Christian Louboutin , they sell out. Keeping up with the demand is becoming quite difficult.

http://www.trendyedhardy.com/

It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of post. I will be your loyal reader. Thanks again.

Ed Hardy Men Classic

shirt
ed hardy men Classic

shirt

Hey, it seems that you are

Hey, it seems that you are good at internet marketing and Drupal manufacture. You can join Freelancer.com to get more projects regarding both subject. Use this code BUILDIT4ME to get more advantages from the site. Good luck.

Christian Louboutin Shoes

Great post, thank you for sharing, look forward to read more of your post!Nobody can ignore the existence of Christian Louboutin shoes in the fashion world. And what makes
Christian Louboutin so remarkable?Its exquisite quality, fine craftsmanship, sexy high heels, quirky designs and of course the red outsole known as the symbol of
Christian Louboutin shoes.

I will look into being more

I will look into being more selective with my commands to the bootstrap routine. I guess it really depends on your requirements.

holiday to costa blanca

Thanks. I've been using

Thanks. I've been using flash in my Drupal site too. They work pretty good and blend perfectly. I want to do some research about using flash with Drupal but with other module as well. Maybe I'll post some of the result here. Thanks.
restaurantes en madrid

Hey

Nice article. Thanx for sharing.

Gregor S.
Kostenlose SMS

I still got an error when

I still got an error when trying to sync the flash on my Drupal based site. I can't seem find the error part. I've read your post, but it seems that's not my problem. Do you have any idea where can I find other answer? Thanks
1 hour payday loans

links of london Sweetie Bracelets

links of london Friendship Bracelets links of london Friendship Bracelets links of london Friendship Bracelets links of london Friendship Bracelets links of london Friendship Bracelets links of london Friendship Bracelets links of london Friendship Bracelets links of london jewellery links of london Friendship Bracelets links london Earrings links london Earrings links london Earrings links london Earrings links london Earrings links london Earrings links london Earrings links london Earrings links london Earrings links london Earrings links of london Pendant links of london Pendant links of london Pendant links of london Pendant links of london Pendant links of london Pendant links of london Pendant links of london Pendant links of london Pendant links of london Pendant

nice

hottiffanyshop

Morality is not really the doctrine of how to make ourselves happy but of how we are to be worthy of happiness.

mens tiffany bracelets
mens tiffany pendant

Nice articles, but I am not

Nice articles, but I am not clear about the point you mentioned about how to distinguish fake and real louis vuitton handbags.