Socket.connect is non-blocking, which in this situation means the rest of the execution chain for your method will continue to run while the socket attempts to connect. The IOError will only be thrown when there is no host specified. The security restrictions that trigger the SecurityError are typically lower for local files when run from a trusted folder (which is the case if you are using flex builder or have set it up manually) so its unlikely the SecurityError will be thrown for your situation.

As for why your events are not firing it could possible because you are defining sock as a variable local to the scope of the connect1 function and not on the class Bar, which means the garbage collector is free to destroy that instance whenever it feels like, likely before the events fire. Try declaring sock as a public or private var on the Bar class instead. eg:

public class Bar
{
public var sock:Socket;

public function connect1():void
{
sock = new Socket();
...
}
}


hth,
Drew


On 03/01/2008, at 10:16 PM, saju_flex wrote:

I have the following code that *should* fail :

public class Bar {
public function connect1():void {
trace("t1");
var sock:Socket = new Socket();
sock.addEventListener(IOErrorEvent.IO_ERROR, ioerr_handler);
sock.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
security_handler);
sock.addEventListener(Event.CONNECT, connect_handler);
try {
sock.connect("nonexistent.fubar.bom", 80);
trace("this should not print");
} catch (e:IOError) {
trace("caught error " + e);
} catch (e:SecurityError) {
trace("sec error " + e);
}
trace("t2");
}

private function connect_handler(event:Event):void {
trace("MOJO connect() OK" + event);
}
private function ioerr_handler(event:IOErrorEvent):void {
trace("MOJO IOERROR EVENT OCCURRED " + event);
}

private function security_handler(event:SecurityErrorEvent):void {
trace("MOJO SECERROR EVENT OCCURRED " + event);
}
}
}

When running in a debug flashplayer I am seeing the trace msg "this
should not print" printing to logs. Also neither the IOErrorEvent
handler nor the SecurityErrorEvent handler fire. Also neither the
IOError nor the SecurityExceptionError are being thrown. I am loading
the file off local disk.

Any idea why no error is being thrown ?

-srp




Reply via email to