I have written an ActionScript client program that tries to connect to a local java server that listens on port 8787.
The code is the following:
import flash.display.*;
import flash.events.*;
import flash.net.Socket;
import flash.system.Security;
public class Main extends Sprite {
// Properties
private var socket:Socket;
// Constructor
public function Main() {
Security.loadPolicyFile("xmlsocket://localhost:8787");
socket = new Socket();
socket.addEventListener(Event.CONNECT, onConnectHandler);
socket.connect("192.168.0.3", 8787);
}
// Methods
private function onConnectHandler(event:Event):void {
trace("The socket is now connected...");
var myspr:Sprite = new Sprite();
myspr.graphics.beginFill(0x000000);
myspr.graphics.drawCircle(50, 50, 60);
myspr.graphics.endFill();
addChild(myspr);
}
}
But in the flash cs4 IDE i get the following message:
Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error.
at Main()
While when i drop the swf in firefox i get:
SecurityError: Error #2010: Local-with-filesystem SWF files are not permitted to use sockets.
at flash.net::Socket/internalConnect()
at flash.net::Socket/connect()
at Main()
Note: instead of “192.168.0.3”, i have also test 127.0.0.1 and localhost without success.
When developing locally, you need to add your swf to Flash’s Global Security Settings permissions:
Flash Settings Manager
Add the location of your local swf to the trust file list and set it to “always allow.”