-1

I just started a project in flash, but it can't startup XMLSocket.

My code:

import Network.CommunicationBootstrap;

var network:CommunicationBootstrap = new CommunicationBootstrap();
network.start("127.0.0.1", 30000);

Package Network classs CommunicationBootstrap:

package Network {
import flash.net.XMLSocket;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;

public class CommunicationBootstrap {

    private var socket:XMLSocket = new XMLSocket();

    public function CommunicationBootstrap() {
        socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
    }

    public function start(ip:String, port:int):void {
        this.socket.connect(ip, port);

        trace("Testing this out!");
    }

    private function ioErrorHandler(event:IOErrorEvent):void {
        trace("ioErrorHandler: " + event);
    }

    private function securityErrorHandler(event:SecurityErrorEvent):void {
        trace("securityErrorHandler: " + event);
    }

}

}

What my errors are: ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket Error. URL: 127.0.0.1"] securityErrorHandler: [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048: Security sandbox violation: file:///C|/Users/iufrs/Documents/AS3/1/Torn.swf cannot load data from 127.0.0.1:30000."]

(gotten by trace and the 2 events)

user2528595
  • 75
  • 2
  • 5

1 Answers1

1

This is (as the message hints) due to the sandbox your swf is running in.

from the docs

Local file describes any file that is referenced by using the file: protocol

Which is what you are doing here.

Further:

The local-with-filesystem sandbox—For security purposes, Flash Player places all local SWF files and assets in the local-with-file-system sandbox, by default. From this sandbox, SWF files can read local files (by using the URLLoader class, for example), but they cannot communicate with the network in any way. This assures the user that local data cannot be leaked out to the network or otherwise inappropriately shared

This is what is causing you to see the error.

If you intend your swf to be hosted by a web server, then you should make sure the swf can be loaded from your webserver running on 127.0.0.1, and you should load it over http, e.g. as http://127.0.0.1/YourSwf.swf

If you want to run your sef from the filesystem, you need to compile it to run in the 'local-with-networking' sandbox, the link explains how.

.

Steve Allison
  • 1,091
  • 6
  • 6