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
{
impo开发者_如何转开发rt 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!
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).
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:
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.
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!
精彩评论