Flash/ActionScript strategy file crossdomain.xml to solve cross-domain problems

I encountered a Flash security sandbox error when I was taking a video screenshot. I searched for a lot of methods on the Internet. After working for a long time, I was upset and finally solved it. Write it down here.


Use BitmapData.draw Flash to pop up this error
SecurityError: Error #2123: Security sandbox conflict: BitmapData.draw: xxx.swf cannot access null. You are not authorized to access any policy files.


Solution: (I solved it this way anyway)

1. Modify the crossdomain.xml code as follows. (Note: Many methods on the Internet do not add encoding to the xml root. I only solved it after adding it.)
This writing method is absolutely not wrong for Flash11 and above, and it will not be missed.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> 
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all" />
<allow-access-from domain="*" to-ports="*"/>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>


2. Add these lines when the stage is created.

Security.allowDomain("*")
Security.allowInsecureDomain("*");
Security.loadPolicyFile("http://xxxx/crossdomain.xml");



3. Save crossdomain.xml as utf-8 format without BOM.
Appendix: Before solving, I used finfo_file to print crossdomain.xml. The result is: application/xml; charset=us-ascii.
After seeing charset=us-ascii, immediately save crossdomain.xml as utf-8, the problem is solved!


That is to say, when flash reads crossdomain.xml, when interpreting the cross-domain-policy byte stream sent back by the server, the encoding is relevant!
If your web server is older, you may need to add mime to respond to crossdomain.xml requests!

<mime-mapping>
    <extension>xml</extension>
    <mime-type>application/xml</mime-type>
</mime-mapping>


That is, Content-Type must return  application/xml.

Or, directly change  crossdomain.xml to txt, crossdomain.txt.




Looking back, let’s talk about the  security sandbox conflict: BitmapData.draw: xxx.swf cannot be accessed.

If NetStream uses the generation mode to create the video, that is, the appendBytes function is used, then the Video cannot be drawn. . .





Guess you like

Origin blog.csdn.net/RoadToTheExpert/article/details/46438009