Problems with Flex security sandbox encountered in development

Source: Internet
Author: User

There are several solutions to the problem of security sandbox encountered in development:

1.

The player can use wildcard characters above 8.0 “*” To allow all domains:
System.security.allowDomain ("*");

If you want to allow multiple domains, you can separate them with commas:
System.security.allowDomain ("www.windshow.com", "windshow.com", "player.windshow.com");

2. About flex read a picture across a domain

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

When a client visits your myfalsh.swf file and your file goes to www.otherserver.com/img/1.jpg, load this image into Flash.

What to do? The simplest method is var l:loader = new Loader;    L.load (New URLRequest ("")); This way if your flash is run directly on the local directory it can also

Load on the server immediately error security sandbox conflict

Look at the loader Load method load (request:.chm::/langref/flash/net/urlrequest.html]urlrequest, Context:.chm::/langref/flash /system/loadercontext.html]loadercontext = null):. chm::/langref/specialtypes.html#void]void

Context:.chm::/langref/flash/system/loadercontext.html]loadercontext, why are you using this? And look at help. Used to set the run domain and set whether the security policy file is loaded
Of course the use method is var lc:.chm::/langref/flash/system/loadercontext.html]loadercontext = new. chm::/langref/flash/system/ Loadercontext.html]loadercontext (TRUE);
var l:loader = new Loader;    L.load (New URLRequest (""), LC); Is that all right? No, No.
And put a security policy file on the other server's root directory under the name:crossdomain.xml better be this name than write code .
Content is

<?xml version= "1.0"?>
<?xml version= "1.0"?>




So there is a big drawback in this way is to put a file on the other server, others will be willing to give you ah? Or you're stupid.
3. It is natural to think of using the proxy method is to use asp,php and other similar programs to read the picture back and pass to Flex
Specific: Put one like getpic.asp on the server and myfalsh.swf the same directory
The code for getpic.asp is
Java Code <% function Rereader (URL) Dim http Set http = server. CreateObject ("Microsoft.XMLHTTP") with HTTP. Open "Get", url,false, "", ""     . Send Rereader =. Responsebody End With Set http = no End Function Dim url url =request.querystring ("url") respo Nse. Clear Response.ContentType = "Image/gif" response.binarywrite rereader (URL) Response. End%>

<%

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

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



Myfalsh.swf kind of code that writes
Java codePrivatevar _loader:loader;Privatevar _loadurl:string; Publicfunction Fileloader (url:string) {_loadurl = URL; _loader =NewLoader ();    _loader.contentloaderinfo.addeventlistener (event.complete,onloadcompleateevent);            _loader.contentloaderinfo.addeventlistener (ioerrorevent.io_error,onloadioerrorevent); }//Load Publicfunction Load ():void{var req:urlrequest =NewURLRequest (_loadurl);    _loader.load (req); } Publicfunction get content ():D isplayobject{ return_loader.content; }Privatefunction Onloadcompleateevent (e:event):void{ This. dispatchevent (NewEvent (Event.complete)); }Privatefunction Onloadioerrorevent (e:ioerrorevent):void{alert.show ("load Error");            This.dispatchevent (New Event (Ioerrorevent.io_error)); }

private var _loader:loader; private var _loadurl:string; public Function Fileloader (url:string) {_lo
    Adurl = 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);
        The Public function get content () is: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 ("Load Error");
        This.dispatchevent (New Event (Ioerrorevent.io_error)); }




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

4.BlaseDS Solution
<mx:remoteobject destination= "Remo" id= "Serviceyellow"
         result= "Resulthandleyellow (event)" Endpoint= "http://109.111.4.123:8080/SNUMSUNG/ MESSAGEBROKER/AMF ">
    </mx:RemoteObject>
To change the IP address in endpoint to the IP address of the server

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.