Flash Cross-domain problem believe that not everyone can encounter, if you publish locally, or directly ctrl+enter in the Flashide preview, will not encounter cross-domain problem, of course, Cross-domain has a prerequisite, that is, Flash is not completely independent, and the outside to do some communication and interaction, If your flash is a completely separate file, without any interaction or data communication with the outside world, you may not consider cross-domain issues, because there is no cross-domain problem.
What is cross domain?
Cross-domain simple is to access other domain name files or resources, such as a.com Flash to access b.com resources, then it will cause cross-domain problems, because a.com and B.Com are not the same domain name.
Why is there a cross-domain problem?
It's not just flash,javascript. Some scripts also have cross-domain problems, this is mainly due to their own security mechanism, because Cross-domain access to some files or resources is a certain risk, he exceeded the scope of the site itself, for the resources outside the station can not audit its security, In the Internet virus Trojan increasingly rampant today, cross domain restricted access is an important solution to its security strategy.
What is the problem with Cross-domain?
There are a lot of cross-domain problems, the most direct is that the access to the file is limited, so that your flash will not work properly, so it is a very headache thing.
Now the Flash has not only as an animation, more data interaction, so communication with the outside as a more interactive medium to show, cross-domain is one of the problems that must be addressed.
Well, maybe someone said, since there are cross-domain problems, then I put the resources under the same domain name is not OK? Well, you can do this, but sometimes we also encounter access to external resources, and in a more formal project, Flash and HTML tend to be open, and many companies are the same, in order to facilitate maintenance and management, so cross-domain problems are easy to appear.
?? Disorderly Huai extracted glare? GUI Pain Zhang Guide The south to the 嫠 of the undercover of the hammer, the 饩 of the Yi-yi-yi-duo Bong Xinsun, the noise Song Mo, 窈 笤, and the 饩 of the. onto
1, flash its own security mechanism settings:
Flash, there is no security restrictions on the operation of the IDE, but the release, there will be a lot of restrictions, Flash has 2 in the way to publish, one is only to access the network, one is to access only local, you can in the file-Publish Settings-flash tab, see, Note that you must be in the Flash file when it is valid, if the current edit is the as file is the wood has this selection menu:
The security level of Flash is already limited here, if you are only accessing the local, then all access to the Web in Flash will be banned, and only access to the network will be prohibited for local file access, so you choose according to the actual use, if you want your flash on the Web, Then choose to only access the network, so you will be sure to test the testing in WebService, local run can be a variety of problems (if there is data communication), such as: Test urlhttp://127.0.0.1/123.swf.
2, ActionScript code settings:
The code is as follows |
Copy Code |
AS2: System.security.allowDomain ("*")//for different HTTP resources System.security.allowInsecureDomain ("*");/for resources that require security verification, such as HTTPS AS3 wording: Flash.system.Security.allowDomain ("*"); Flash.system.Security.allowInsecureDomain ("*"); |
The above is the strict writing, AS3 Fortunately said, we should pay attention to AS2,AS2 is Wood has flash.system this package, but you import Flash.system does not give an error, so if you copy the AS3 code into the run, although everything is normal, but the actual wood has any effect. Be sure to pay attention!
The above code is to allow flash access to any URL resources, if you want to access a specific URL, you can change the * to the URL, if more than one URL, separated by commas, note that Allowinsecuredomain is allowed access to the URL with authentication resources, For example, HTTPS is the beginning, and if you are accessing just plain HTTP, you don't need it.
3, the HTML settings:
If you need to communicate with the page JS, then HTML must have such a parameter:
The code is as follows |
Copy Code |
<param name= "allowscriptaccess" value= "Always"/>
|
Parameter always indicates that script access is always allowed and, if it is never, it is always disallowed.
4. Load external resources:
If you want to read an external file, such as Swf,picture,mp3, and so on, then you need a Cross-domain policy file (crossdomain.xml), which is actually an XML file, specifically:
The code is as follows |
Copy Code |
<?xml version= "1.0"?> <cross-domain-policy> <allow-access-from domain= "www.explorechn.com"/> <allow-access-from domain= "explorechn.com"/> <allow-access-from domain= "223.4.119.191"/> </cross-domain-policy> |
This is the Cross-domain policy file, Allow-access-from domain represents a URL that is allowed to be accessed, and if there are multiple additions, it is OK to allow all the allow-access-from domain = "*".
Need to explain this file how to use, if your flash in a.com, you need to access b.com resources, then put this XML in B.Com root directory can automatically access, of course, you can access other directory policy files.
The code is as follows |
Copy Code |
Flash.system.Security.loadPolicyFile (url:string); |
Through this loadpolicyfile can take the initiative to load a security policy file, pay attention to the above is AS3, AS2 not the same Oh, refer to the above writing.
5. Cross-domain issues for each browser:
ie do not say, this basic no problem, including flash generated by the HTML on IE's support to do a good job, here to talk about the issue of Chrome and FF:
For Flash,ie is the OBJECT tag, but FF and chrome are embed tags, so this is very important, if in debugging, find Firebug and other ToolTips "... is not a Function", We'll look for the following:
1, whether Addcallback successfully registered
2, allowscriptaccess whether to allow always, the default does not allow
3, Flash is completely loaded complete
In general, the 3rd is our most easily encountered, if your flash did not load up to call the function, it is not found this function.
Note that there is another error, "error calling method on Npobject", if this error occurs, be careful:
1, security policy issues, please refer to all the above Solutions
2, their own function errors