Flash Remoting TechNote

How createGatewayConnection determines the URL

When using NetServices.createGatewayConnection() to connect to a Flash Remoting gateway, the URL for the gateway can be determined in multiple ways. This TechNote describes how NetServices.createGatewayConnection() finds the URL and connects to the gateway.

Providing a URL in createGatewayConnection

The createGatewayConnection method can accept a URL, but this is not a required argument. If a URL is provided to the method, NetServices will always connect to the provided URL. Because the URL is an optional argument, the Flash Remoting determines the gateway to be used as described in the following sections.

Playing in Authoring mode

When a URL is not provided to createGatewayConnection, the method will need to find a valid URL. The first thing this method does is determine if the Flash movie is in Authoring mode or being played from a web server. The createGatewayConnection method does this by looking at the current value for the root URL of the Flash movie ( _root._url ). If the root URL does not start with either http:// or https://, the method determines the movie is being run in Authoring mode. In this situation, the method will automatically use the value defaultGatewayURL.

Using HTML OBJECT and EMBED tags for the gateway URL

If createGatewayConnection determines that the root URL does start with http:// or https:// then the method checks for the existence of gatewayUrl. You can define the gatewayURL by using a PARAM tag (for Internet Explorer) and an EMBED tag (for Netscape) in the HTML OBJECT tag for the Macromedia Flash player. The following example shows how you can use these tags to specify the URL for the gateway server:

<OBJECT classid="clisd:D27CDB6E-AE6D-11cf-96B8-444553540000"
<PARAM NAME=flashvars VALUE="gatewayUrl=http://localhost:8500/
<PARAM NAME=movie VALUE="moviename.swf">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#000099>

<EMBED src="moviename.swf"

Note: The new PARAM and EMBED object tags are highlighted.

Known issues when relying on the defaultGatewayURL

If the HTML document does not contain a PARAM tag defining gatewayUrl, then createGatewayConnection will use the defaultGatewayURL. Before createGatewayConnection can use this URL, createGatewayConnection must modify the value to make sure that the host domain and port match up to the current root's URL and port address. Currently, there is a known issue with NetServices that causes a limitation when relying on the defaultGatewayURL. When NetServices modifies the defaultGatewayURL, it should allow for the Macromedia Flash application to connect to a gateway on the same domain. However, the current version will only allow the application to connect to the same host and port that the SWF is served from.

For example, the current defaultGatewayURL is set to:


Because the Flash movie is now being hosted off a web server, localhost is no longer a valid address. CreateGatewayConnection will then grab the host name and port from the root URL of the Flash movie and replace the defaultGatewayURL's hostname and port with this new information.

The current root URL ( _root._url ):

createGatewayConnection grabs the hostname and port:

and then modifies the defaultGatewayURL with this information:

Once the modifications have been made, createGatewayConnection uses the new URL and then connects to the gateway.

There are multiple ways to work around this issue with NetServices. The easiest solution is to not rely on defaultGatewayURL and provide the correct gateway address in the PARAM tag. It is also possible to directly set the gatewayURL variable (instead of using Flashvars):

var gatewayURL = "";

Another solution is to host all the SWF files on the same host and port for different sites. This approach causes NetServices to replace the host and port with the correct location.

One final workaround is to provide the URL in the createGatewayConnection(). This will work, however it is not a recommended solution. Hard coding the gateway URL into the Flash application means that if the gateway changes, (for example, if you are no longer using localhost), then the address has to be directly changed in the source file. This approach requires that the FLA file itself must be modified and then a new SWF must be published in order to change the URL.

Additional information

For more details about createGatewayConnection() and setDefaultGatewayUrl() please refer to the Using Flash Remoting documentation.

Last updated: September 3, 2002
Created: May 22, 2002
ID: 16352
Product: Flash Remoting
Versions: MX
OS: All
Browser: All
Server: None
Database: None
Former ID: N/A