Saturday, May 27, 2006

How to access or send data across the domain via flash

Prior to flash player 7, this was not very tough job to load/send data across domain. Now this is little bit tricky and more secure.
As we know, to access data across the domain, we need an XML file known as crossdomain.xml.

But first we need to know about domain comparison.
case 1: www.yourdomain.com == www.yourdomain.com
case 2: http://193.147.45.76 != www.somedomain.com
case 3: www.somedomain.com != http://somedomain.com
case 4 www.sub.somedomain.com != www.somedomain.com

In case of data loading no error will be shown while on loading clips, you will get a warning message.


A crossdomainpolicy file is basically a XML file with a specified format...

/*[ignore these comments]
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="www.somedomain.com" />
<allow-access-from domain="http://somedomain.com" />
<allow-access-from domain="http://195.134.23.67" />
<allow-access-from domain="*.somedomain.com" />
<allow-access-from domain="*" />
<allow-access-from domain="www.FromNonsecureToSecureDomain.com" secure="false" />
</cross-domain-policy>
*/

Its name must be saved as crossdomain.xml and must resides in root folder of the domain.
In flash player version 7r19 or later, one more feature is added and that allows us to keep policy file in arbitrary positions.
System.security.loadPolicyFile
Using this API, one can place policy files in arbitrary locations, rather than the default location at the root. With this API, you can also serve policy files directly from XMLSocket servers and specify XMLSocket connections to ports below 1024.

DEL

No comments: