09
Sep
08

When to use Security.loadPolicyFile(url:String) in your Flex app

Often is the case where you’ll need to test your application on multiple boxes and for multiple clients, so you can’t just assume the crossdomain.xml file exists at the root of the domain or even in the same location…this forces you to pass in the crossdomain file’s location at run-time and then load it into the Flash Player before you make your first request for data / et al, and so I often wondered when the best time was to do this to ensure the file was loaded and thus eliminate any possible race conditions.

After searching around on the Flex 3 docs, I read that the best place for this call was in the root Application class’s preinitialize event handler — oddly enough I found this tidbit in the “Loading modules from different servers” section of the docs, but I also ran into this very race condition just recently in a web services based application as well.


5 Responses to “When to use Security.loadPolicyFile(url:String) in your Flex app”


  1. 1 Aryan
    October 26, 2008 at 2:11 pm

    Nice blog dude. helped me a lot in learning flex.
    I’ve had this problem for about 2 months now, and still not fixed. It’s related to this post
    can you see if u know the solution? apreciate ur help in advance
    Server is working fine because it’s been tested with a C# client

    Flex ==> Socket?!?!?!?
    Flex client connects to my server. (Event.CONNECT fires)
    It’s able to send messages to server
    It DOESN’T receive any message. (DataEvent.DATA won’t fire)
    policy running on IIS (localhost)

    the project is on my desktop not on IIS.

    Security.allowDomain(“*”);
    Security.loadPolicyFile(“http://localhost/crossdomain.xml”);
    socket = new XMLSocket(“10.0.0.3″ , 8000);
    socket.addEventListener(DataEvent.DATA , OnData);
    socket.addEventListener(Event.CONNECT , onConnect);
    socket.addEventListener(IOErrorEvent.IO_ERROR, OnError);
    socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, OnSecurity);
    socket.addEventListener(Event.CLOSE, onDisconnect);
    socket.connect(“10.0.0.3″ , 8000);

    both server and client are on the same machine.
    server is on desktop 2.
    there is no security error

    ANY IDEA WHY I AM NOT ABLE TO RECEIVE DATA THROUGH SOCKET?

  2. 2 tanvir
    April 20, 2009 at 6:47 am

    Hey Aryan,
    Did you solved your problem yet ????

    i am also facing this sort of problem …..

    if you solved that plz share the solution here.

    If anyone else have any solution or suggestion regarding the aryan problem plz provide it here.

  3. 3 Alina
    April 29, 2009 at 1:53 pm

    socket.addEventListener(ProgressEvent.SOCKET_DATA, socket_data_handler);

    Different event

  4. July 31, 2009 at 10:01 am

    Hi guys,

    About sockets, Flex must read the crossdomain from your socket (so with a different port than classic HTTP)…

    From your socket server, you need to detect the first connection and send the crossdomain.xml content, than Flex reconnect to the server and its fine!

  5. November 6, 2009 at 1:57 pm

    Anyone know if it’s possible to get cross domain content using LoadXML?


Leave a Reply