Feasible Impossibilities - The personal weblog of Robert M. Hall


Send More Variables to Flash 6 Player Using New Parameter

By Robert M. Hall of Feasible Impossibilities

I saw that Macromedia is running a contest in their Designer Developer Area where you can submit tips for using Macromedia products and possibly win an iMac! Well I tried to think of something I could submit and came up with this and submitted it a few minutes ago. Hope its useful!

Introduction: A new parameter for both OBJECT and EMBED, FlashVars, is available for the Flash 6 player. It allows a much greater amount of variable information to be passed from your html document than previous methods reliably allowed. In the past an efficient way for getting dynamically changing information into a Flash document was to pass that information in the form of appended URL encoded data after the name of your .swf document (the NAME parameter for OBJECT tag and the SRC parameter for EMBED)

Here is an example where the variable foo will be passed the value bar from the html page loading the .swf file named document.swf :

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" ID=sign_on WIDTH=100% HEIGHT=100%>
<PARAM NAME=movie VALUE="document.swf?foo=bar">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=menu VALUE=false>
<PARAM NAME=bgcolor VALUE=#000000>
<EMBED src="document.swf?foo=bar"
quality=high menu=false bgcolor=#000000 WIDTH=100% HEIGHT=100% TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>
</OBJECT>


This is an easy way to get information that may change into your flash file at load time. Typically a server side function would determine the correct value of foo and at the time the html page with the above tags is requested, the correct value would be dynamically inserted it into the html. From here it is passed into the flash file and available for use. This is essentially a GET request with appended URL encoded information.

With versions of the Flash player prior to 6, this method could fail if the amount of variables exceeded a certain amount of characters in length. This is a limitation of certain browsers and servers in their ability to handle large GET requests.

With the release of the Flash 6 player a new parameter for both the OBJECT and EMBED tags was introduced. Meet: FlashVars. By using the new FlashVars parameter a much greater amount of information can be passed to the Flash document. Here is an example of accomplishing the same objective as above but instead of appending the data to the movie name in URL encoded format, we use the new FlashVars parameter.

  <OBJECT 
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" 
  ID=sign_on WIDTH=100% HEIGHT=100%>
  <PARAM NAME=movie VALUE="document.swf">
  <PARAM NAME=FlashVars VALUE="foo=bar">
  <PARAM NAME=quality VALUE=high>
  <PARAM NAME=menu VALUE=false>
  <PARAM NAME=bgcolor VALUE=#000000>
  <EMBED src="document.swf" FlashVars="foo=bar" 
quality=high 
  menu=false bgcolor=#000000 WIDTH=100% HEIGHT=100% 
TYPE="application/x-shockwave-flash" 
PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>
  </OBJECT>


This new method is especially handy when used with server side scripting such as ColdFusion MX or PHP to dynamically create the values of FlashVars that will be embedded in the HTML document and in turn passed into the .swf document we refer to in the object and embed tags. You could pass in data from a cookie in this method or other personalized information. Below is an example using PHP that would assign the current GMT date & time from your server to the variable "gmt" and the visitors IP address to the variable "ip" which in turn would be placed in the FlashVars parameter and passed into your flash document being referenced by the object and embed tag in question.

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" ID=sign_on WIDTH=100% HEIGHT=100%>
<PARAM NAME=movie VALUE="document.swf">
<PARAM NAME=FlashVars VALUE="<? echo "gmt=".urlencode(gmdate("D, d M Y H:i:s"))."&ip=".$REMOTE_ADDR; ?>">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=menu VALUE=false>
<PARAM NAME=bgcolor VALUE=#000000>
<EMBED src="document.swf" FlashVars="<? echo "gmt=".urlencode(gmdate("D, d M Y H:i:s"))."&ip=".$REMOTE_ADDR; ?>" quality=high menu=false bgcolor=#000000 WIDTH=100% HEIGHT=100% TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>
</OBJECT>

Here is an example of what that would end up looking like after being processed by the server:

<PARAM NAME=FlashVars VALUE="gmt=Sun%2C+26+May+2002+17%3A22%3A03&ip=192.168.0.1">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=menu VALUE=false>
<PARAM NAME=bgcolor VALUE=#000000>
<EMBED src="document.swf" FlashVars="gmt=Sun%2C+26+May+2002+17%3A22%3A03&ip=192.168.0.1" quality=high
menu=false bgcolor=#000000 WIDTH=100% HEIGHT=100% TYPE="application/x-shockwave-flash"
PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>
</OBJECT>


The thing to note is that any variables passed into Flash using this method appear on the main timeline or _level0 of your movie.
Using the FlashVars parameter you can avoid the initiations imposed on the GET request by various browsers and servers, thus you are able to pass much more information into your Flash .swf document.

Another benefit for webmasters is that if you are recording the data from GET request in your web server log files, they wont be clogged up with extra data in the url fields. This might be especially attractive to webmasters who filter certain types of GET request from their server for security reasons, or for webmasters who run IDS (Intrusion Detection systems) such as Snort or other fingerprint based IDS's that may have false positives triggered by large GET requests.

Happy Coding! -Rob



About Adobe Community Experts

Recent Status:

 
Loading Recent Status...

Feeds

XML Feed (RSS 1.0) 
XML: Atom Feed 

Google Translation

Friends Flash Blogs
Flash Enabled - Book
Darron Schall
Branden Hall
Scott Janousek
Alessandro Pace
Richard Leggett
Jim Armstrong
Jonathan Kaye
Guy Watson
Marco Casario
Grant Skinner
Veronique Brossier
Marcos Weskamp
Beau Amber
Craig Swann
Natalie Zee
Lord Alex Leon
Jesse Warden
Chafic Kazoun
Brajeshwar Oinam
Matt Voerman
Aral Balkan
Robert Penner
Andreas Heim
Justin Everett-Church
Sam Robbins
Keith Peters
Lee Brimelow
Patrick Minneault
Mario Kilngermann
Peter Joel Hall
Paul Ortchanian
Steve Webster
Colin Moock
Alessandro Crugnola
Josh Dura
Burak Kalyci
Eric Dolecki
Dave Yang

Adobe Staff Blogs

Aggregators
MXNA Aggregator
Adobe Blogs

Flash Resources
Adobe Labs
Adobe Developer Center
OSFlash
Flash Enabled Book
Ant Mobile Software
Flash Components
Flash Magazine
UltraShock
Were-Here
Chattyfig/Flashcoders
ActionScript.org
Flash Devils
Layer 51 - Prototype
Actionscript.com

Mobile & Device Resources
Microsoft Pocket PC
Pocket PC Thoughts
SmartPhone Thoughts
Gizmodo
Nokia

More Links -->

Archives
01 Feb - 28 Feb 2001
01 May - 31 May 2001
01 Jul - 31 Jul 2001
01 Sep - 30 Sep 2001
01 Oct - 31 Oct 2001
01 Nov - 30 Nov 2001
01 Dec - 31 Dec 2001
01 Jan - 31 Jan 2002
01 Feb - 28 Feb 2002
01 Mar - 31 Mar 2002
01 Apr - 30 Apr 2002
01 May - 31 May 2002
01 Jun - 30 Jun 2002
01 Jul - 31 Jul 2002
01 Aug - 31 Aug 2002
01 Sep - 30 Sep 2002
01 Oct - 31 Oct 2002
01 Nov - 30 Nov 2002
01 Dec - 31 Dec 2002
01 Jan - 31 Jan 2003
01 Feb - 28 Feb 2003
01 Mar - 31 Mar 2003
01 Apr - 30 Apr 2003
01 May - 31 May 2003
01 Jun - 30 Jun 2003
01 Jul - 31 Jul 2003
01 Aug - 31 Aug 2003
01 Sep - 30 Sep 2003
01 Oct - 31 Oct 2003
01 Nov - 30 Nov 2003
01 Dec - 31 Dec 2003
01 Feb - 29 Feb 2004
01 Mar - 31 Mar 2004
01 Apr - 30 Apr 2004
01 May - 31 May 2004
01 Jun - 30 Jun 2004
01 Jul - 31 Jul 2004
01 Sep - 30 Sep 2004
01 Oct - 31 Oct 2004
01 Nov - 30 Nov 2004
01 Dec - 31 Dec 2004
01 Feb - 28 Feb 2005
01 Mar - 31 Mar 2005
01 Apr - 30 Apr 2005
01 May - 31 May 2005
01 Jun - 30 Jun 2005
01 Jul - 31 Jul 2005
01 Aug - 31 Aug 2005
01 Sep - 30 Sep 2005
01 Oct - 31 Oct 2005
01 Nov - 30 Nov 2005
01 Feb - 28 Feb 2006
01 Mar - 31 Mar 2006
01 May - 31 May 2006
01 Jun - 30 Jun 2006
01 Jul - 31 Jul 2006









Hosted By:


Powered By Pivot

Copyright 1997-2006 Robert M. Hall, II, Inc. DBA Feasible Impossibilities All Rights Reserved