The NetConnection class (client-side)
If an HTML page containing a Flash application (SWF file) is accessed with a different
domain name than the domain name the SWF file uses to access Flash Media Server, the
connection to Flash Media Server will not be successful. This is a security feature of Flash
Player. But in some cases, this may be inconvenient.
For example, if a web page containing a Flash application is served on an intranet from http:/
/deptserver.mycorp.com, it can also be accessed from http://deptserver. However, if the page is
accessed from the URL http://deptServer/tcpage.htm, but the SWF file specifies
deptServer.mycorp.com as the
method, the SWF file will not successfully connect to Flash Media Server. Similarly, if the web
page and SWF file are accessed from the URL http://deptserver.mycorp.com/tcpage.htm, but
the SWF file uses the URL rtmp://deptserver as the
connect to the server.
You can do a few things to prevent the security policies from inconveniencing you or your
users. The easiest way is not to include a server name in the
applicable only if Flash Media Server and the web server are running on the same machine.)
To do so, leave off the second slash in
instruct Flash Player 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");
Another way to avoid the security problem is to use a bit of JavaScript in your HTML page.
Assuming the SWF file uses a fully qualified domain name URL to access Flash Media Server,
the following JavaScript redirects the web page to an explicitly named full URL:
<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 Media Server, you can create address ("A") records to
point a host name to that IP address. For example, flashcom.mycorp.com could map to the
computer that is running Flash Media Server and has 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.)
parameter in the
targetURI
. For example, the following commands will
targetURI
NetConnection.connect()
parameter, the SWF will not
targetURI
parameter. (This is
targetURI
The NetConnection class (client-side)
49
Need help?
Do you have a question about the FLASH MEDIA SERVER 2-DEVELOPING MEDIA and is the answer not in the manual?