NetServices.setDefaultGateway( )

NetServices.setDefaultGateway( ) MethodFlash 6

sets a default URL for a gateway connection
NetServices.setDefaultGateway(url)

Arguments

url

A string containing the URL of a Flash Remoting gateway adapter.

Description

The setDefaultGateway( ) method is a way that you can define a URL for your NetConnection object but allow it to be overridden by a URL passed from the HTML page that houses your Flash movie. In this way, a URL can be set up in the movie for testing or deployment, but if the URL has to change at any time in the future, the URL can be passed to the Flash movie using the gatewayURL variable.

After setting up the default URL using this method, the createGatewayConnection( ) method can be called with no arguments to create a NetConnection object.

Example

The following code shows the basic syntax of the setDefaultGateway( ) method:

#include "NetServices.as"

if (connected == null) {
  connected = true;
  NetServices.setDefaultGateway("http://127.0.0.1/flashservices/gateway");
  var my_conn = NetServices.createGatewayConnection( );
}

To override the default gateway URL, the gatewayURL variable can be passed to the movie using the FlashVars attribute in the HTML page that embeds the .swf file:

<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>

In this example, the FlashVars attribute contains the name/value pair of gatewayURL and the path to the Flash Remoting gateway on my server. You should update it for your server:

gatewayURL=http://www.flash-remoting.com/flashservices/gateway

The gatewayURL is a variable that the NetConnection object is expecting. It overrides any gateway URL set via setDefaultGateway( ) but does not override a URL set via createGatewayConnection( ). Therefore, you should not pass a URL to createGatewayConnection( ) when using the FlashVars approach.

See Also

The NetConnection class, NetServices.createGatewayConnection( ); Chapter 4



    Part III: Advanced Flash Remoting