1

I'm having trouble with a XMLSocket script in AS3. I have a java server and i'm trying to send a XML data, but the server isn't recieving anything. The most suprising is that my script worked very well a month ago, and now my IOError listener returns me :

"Error #2031: Socket error. URL: 127.0.0.1 at test() at Client_fla::MainTimeline/frame1()"

and my SecurityError listener :

"Error #2048: Security Sandbox violation : file:///C|/Documents%20and%20Settings/Zeph/Bureau/Client.swf cannot load data from 127.0.0.1:18000. at test() at Client_fla::MainTimeline/frame1()"

I tried to change IP, I tried on another computer, I tried to pull a former version of my script, which was unchanged, with no result.

I just can't understand why it stopped working like this. Here is my script :

package
{

    import flash.net.XMLSocket;
    import flash.events.*;
    import flash.display.MovieClip;

    public class test extends MovieClip 
    {

        public function test()
        {
            trace("pouet");
            var xmlsock:XMLSocket = new XMLSocket(); 
            xmlsock.connect("127.0.0.1", 18000);
            var xmlFormattedData = new XML('<message pseudo="Nix" value="Coucou !"/>'); 
            xmlsock.send(xmlFormattedData);
            xmlsock.addEventListener(DataEvent.DATA, onData);
            xmlsock.addEventListener(IOErrorEvent.IO_ERROR, ioerror);
            xmlsock.addEventListener(SecurityErrorEvent.SECURITY_ERROR, secuerror);
            xmlsock.send(xmlFormattedData);

        }

        private function onData(event:DataEvent):void 
        { 
            trace("[" + event.type + "] " + event.data); 
        }


        private function ioerror(event:IOErrorEvent):void 
        { 
        trace(event);
        }

        private function secuerror(event:SecurityErrorEvent):void 
        { 
        trace(event);
        }

    }

}

I'm getting mad with this, does anyone have an idea?

Thanks for reading!

Zeph
  • 25
  • 4

2 Answers2

0

As your error is indicating, you're experiencing a sandbox security violation. This means that Flash won't allow assets from application domains other than its own. There are basically two fixes, one much simpler than the other:

  1. Read up on how to create and load crossdomain xml. This is simply a "policy" on the server that your running flash application reads. It can be tricky to set up correctly, but this is the generally accepted route.

  2. On your output settings, under "local playback security" you may be able to check "access network files", instead of "access local files only" - and solve your problem quickly.

Hope that helps!

Bosworth99
  • 4,206
  • 5
  • 37
  • 52
  • I tried both of your solutions, but none is working. I wrote a crossdomain containing (I put a space after http: because the site made automatically a link) and put it in the folder where my .swf and sources are, but the same message is coming. Did I do it correctly? – Zeph Mar 14 '11 at 22:31
  • Yeah - like I said, it can be kind of tricky to set up. Other things: I usually implement a DTD as well, like: . One other thing - placement of the xml is important. You should place it at the **root level** of your site. Placing it elsewhere will render it ignored. – Bosworth99 Mar 15 '11 at 00:30
  • Heyo - just found this detailed article about setting up a socket policy: http://www.adobe.com/devnet/flashplayer/articles/flash_player9_security_update.html . It may just be a crossdomain.xml fix, but it may require more, depending on your configuration. – Bosworth99 Mar 15 '11 at 00:43
0

the error suggests, that you are running a flash application from your local file system and this application wants to make a network request (to your java server).

This is not allowed by default. You can do one of two things:

  • Update your Global Security Settings in your flash player (right click, advanced settings, global security settings, then set the flash file or the whole folder to be allowed to do network requests)

  • Run your flash application from a webserver (and make sure, that a crossdomain.xml is in place on the java server).

ghost23
  • 2,150
  • 1
  • 20
  • 35
  • I used wamp to test my application on a server (with a crossdomain), and it just worked. Thank you very much! – Zeph Mar 16 '11 at 12:52