Using Communication Objects > NetConnection object (client-side)

 

NetConnection object (client-side)

If an HTML page containing a movie is accessed differently (with regard to domain names) from the way the movie itself accesses the Flash Communication Server, then the connection will not be successful. This is a security feature of the Flash Player. But in some cases, this may be inconvenient.

For example, if a web page containing a movie is served on an intranet from, http://deptserver.mycorp.com, it can also be accessed simply by http://deptserver. If the page is accessed via, http://deptServer/tcpage.htm, but the movie specifies deptServer.mycorp.com in as targetURI, then the movie will not make a successful connection to the server. Similarly, if the web page and movie are accessed as http://deptserver.mycorp.com/tcpage.htm, but the movie specifies rtmp://deptserver as targetURI, it will not connect.

There are a few things you can do to prevent the security policies from inconveniencing you or your users. First, and easiest, is not to include a server name in targetURI. (This is applicable only if the Flash Communication Server and web server are running on the same machine.) To do so, leave off the second slash in targetURI. For example, the following commands will make the Flash Player attempt to connect to the same host and domain as the web server the SWF file was served from.

nc = new NetConnection();
nc.connect("rtmp:/myApp");

Second, there is a bit of JavaScript you can use in your HTML page to avoid the security problem. Assuming the movie uses a fully qualified domain name URL to access the Flash Communication Server, this JavaScript redirects the web page to an explicitly named full URL, like this:

<SCRIPT language="javascript">
// if the URL didn't have the domain on it
if (document.URL.indexOf("mycorp.com") == -1) {
    // redirect to a version that does   
    document.URL="http://deptServer.mycorp.com/tcpage.htm";
}
</script>

Finally, if you own a domain name, have access to the DNS records of that domain name, and have a static IP address for your Flash Communication Server, you can create address ("A") records to point a host name to that IP address. For instance, flashcom.mycorp.com could map to the machine running the Flash Communication Server and having an IP address provided by your IT department or ISP. Your web pages can continue to be hosted by whatever means you are currently using. ("CNAME" records are recommended if you need to forward traffic to a server that has a DNS-accessible host name but may or may not have a static IP address.)