Flash Remoting - Setting the alternate gateway URL through FlashVars
When we are working with Flash Remoting we will need to set a URL for our Flash Movie to communicate through to the server. This URL is often specified as an absolute URL in the flash movie - eg, http://www.mysite.com/flashremoting/.
If we are to stage the site on a different domain and still want to access the Flash Remoting, we will need to set up a “crossdomain.xml” file that allows the staging domain to access the Flash Remoting Service - (See ‘Loading external data from Flash‘). This is achieved by creating a XML file named “crossdomain.xml” on the production domain and defining a set of properties specifying which other domains are allowed access its data (Remoting, XML etc).
This all works nicely when we are working with a contained Flash Movie, allowing us to maintain the state on a remote domain. What happens when we wish to access that state information on a different domain? When switching from Flash to another language (say PHP) you will lose your session information. When we are to “break” out from the Flash into an HTML process (- lets say a HTML checkout process) accessing the ‘State’ of the session will not be available as the cookie is set for the Remoting Domain, not the one serving our local HTML. (See ‘sharing a session across multiple domains‘).
If our staging server is a direct copy of the production server (or slightly modified) we would want to be able to specify a different Gateway URL for the flash player to load. Instead of authoring a different Flash Movie for each server (staging or production) we need to be able to change the absolute URL external. One of the ways we could do this is by parsing it in through the HTML.
FlashVars allow us to communicate between the HTML and the Flash Player. When we use the FlashVars parameter in the embed HTML code we can place variables on the root of the movie. This Adobe Flash TechNote article defines the basic use of the FlashVars capability.
We can specify a default Gateway URL to be the production server in our ActionScript like so:
NetServices.setDefaultGateway(”http://www.myproductionserver.com/flashservices/gateway”);
Using the Flash Vars we can overwrite the gateway URL through the HTML, allowing us to seperate out the Gateway URL for Flash Remoting into the HTML, so we can make a quick change without having to republish/export a new SWF file.
An example of an embed showing this in action is as below:
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/ swflash.cab#version=6,0,0,0" WIDTH="550" HEIGHT="400" id="mymovie" ALIGN=""> <PARAM NAME=movie VALUE="mymovie.swf"> <PARAM NAME=FlashVars VALUE="gatewayURL=http://www.flash-remoting.com/flashservices/gateway"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="mymovie.swf" quality=high bgcolor=#FFFFFF WIDTH="550" HEIGHT="400" NAME="Untitled-2" ALIGN="" TYPE="application/x-shockwave-flash" FlashVars="gatewayURL=http://www.flash-remoting.com/flashservices/gateway" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"> </EMBED> </OBJECT>
Thanks to O’Reilly Flash Remoting: The Definitive Guide
IMPORTANT NOTE: You then shouldn’t specify the URL when creating the gateway service, let it be handled by the NetServices which will have the FlashRemoting URL specified.






Nice article man.
Comment by Richard Lee — September 8, 2006 @ 9:39 pm
I think This is a very good idea.
Thanks for your advice…
Comment by kral oyun — February 4, 2008 @ 11:13 am