-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBrowserSocket.as
More file actions
52 lines (41 loc) · 1.66 KB
/
BrowserSocket.as
File metadata and controls
52 lines (41 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package {
import flash.display.Sprite;
import flash.events.*
import flash.net.Socket;
//import flash.display.Stage;
import flash.external.ExternalInterface;
public class BrowserSocket extends Sprite {
public var socket:Socket;
//public var isConnected:Number;
public function BrowserSocket() {
socket = new Socket();
//stage.frameRate = 60;
ExternalInterface.addCallback("first_connection",function(ip:String,port:int):void{
var socket_policy:Socket = new Socket(ip,port);
})
ExternalInterface.addCallback("connect",function(ip:String,port:int):void{
socket.connect(ip,port);
})
ExternalInterface.addCallback("send",function(what:String):void{
socket.writeUTFBytes(what);
socket.flush();
})
socket.addEventListener(flash.events.SecurityErrorEvent.SECURITY_ERROR,function(e:flash.events.SecurityErrorEvent):void{
ExternalInterface.call("browserSocket_securityError",e.text);
})
socket.addEventListener( flash.events.IOErrorEvent.IO_ERROR,function(e:flash.events.IOErrorEvent):void{
ExternalInterface.call("browserSocket_ioError",e.text);
})
socket.addEventListener(flash.events.ProgressEvent.SOCKET_DATA,function(e:flash.events.ProgressEvent):void{
ExternalInterface.call("browsersocket_ondata",socket.readMultiByte(socket.bytesAvailable, "iso-8859-1"));
})
/*
socket.addEventListener(flash.events.Event.CONNECT,function(e:Event):void{alert("connected")
//isConnected = 1;
//this keeps fireing every frame?
})
*/
ExternalInterface.call("browserSocket_ready");
} //end BrowserSocket Constructor
} //end BrowserSocket Class
} //end package