About the security sandbox problem configuration for Flex Crossdomain.xml still having security sandbox issues

Source: Internet
Author: User
Tags php and

About flex reading a picture across domains

For example, suppose your server is www.myserver.com and one of your flex files is located in www.myserver.com/flex/myfalsh.swf

When a client comes to visit your myfalsh.swf file and your file is going to www.otherserver.com/img/1.jpg here to load this image into Flash

What to do?

The first method:

var l:loader = new Loader; 
L.load (New URLRequest (""));   

This way if your flash is run directly on the local directory that can also be placed on the server loading will error the security sandbox conflict look at the loader load method

Load (request:urlrequest, context:loadercontext = null): void 
Context:loadercontext  

Why is this used? And look at the help originally used to set the run domain and set whether the security policy file is loaded
Of course, the way to use

var lc:loadercontext = new  Loadercontext (true);
var l:loader = new Loader; 
L.load (New URLRequest (""), LC);

Is that OK? It's just as bad. Put a security policy file in the root directory of the other server. The name is: Crossdomain.xml better be the name, save more code, the content is:

<?xml version= "1.0"?>
 <cross-domain-policy>
   <allow-access-from domain= "  Www.myserver.com "/>
 </cross-domain-policy>

So there's a big drawback in this way is to put such a file on the other side of the server.

The second method:
It is natural to think that the proxy approach is to use asp,php and other similar programs to read this picture back and then pass it on to Flex
Specific: Put one such as getpic.asp on the server and myfalsh.swf the same directory
The code for getpic.asp is

<%

function rereader (URL) 
Dim http
Set http = server. CreateObject ("Microsoft.XMLHTTP") with 
http 
 . Open "Get", url, False, "", "" 
 . Send 
 Rereader =. Responsebody
End With 

set http = Nothing 
End Function
Dim url
 url =request.querystring ("url" )
 Response. Clear
 Response.ContentType = "Image/gif"
 response.binarywrite rereader (URL)
 Response. End 
%>

The code of the myfalsh.swf is written like this

private Var _loader:loader;
private Var _loadurl:string;
Public Function Fileloader (url:string) {
    _loadurl = URL;
    _loader = new loader ();
_loader.contentloaderinfo.addeventlistener (event.complete,onloadcompleateevent);
_loader.contentloaderinfo.addeventlistener (ioerrorevent.io_error,onloadioerrorevent);
        }

        Load public
function load (): void{
    var req:urlrequest = new URLRequest (_loadurl);
    _loader.load (req);
}

Public function get content ():D isplayobject{
            return _loader.content;
        }

Private Function Onloadcompleateevent (e:event): void{
this.dispatchevent (New Event (Event.complete));
        }

Private Function Onloadioerrorevent (e:ioerrorevent): void{
    alert.show ("Loading error");
            This.dispatchevent (New Event (Ioerrorevent.io_error));
        }

Calling methods

Fileloader (http://www.myserver.com/flex/myfalsh.swf?url=http://www.otherserver.com/img/1.jpg);

The second method is simple, but the efficiency may not be too high.

The third method:
Use Nginx to forward the image resources, such as
Original request:

Http://www.myserver.com/flex/myfalsh.swf?url=http://www.otherserver.com/img/1.jpg

Request after using Nginx forwarding:

Http://www.myserver.com/flex/myfalsh.swf?url=www.myserver.com/flex/img/1.jpg

It is simpler to forward www.myserver.com/flex/img requests to http://www.otherserver.com/img in Nginx.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.