-
Notifications
You must be signed in to change notification settings - Fork 0
/
beckhoffIO.as
75 lines (61 loc) · 1.88 KB
/
beckhoffIO.as
1
package com.mobile { import flash.net.XMLSocket; import flash.errors.IOError; import flash.events.*; import flash.system.Security; public class beckhoffIO extends XMLSocket{ private var xmlBuffer:String; private var lightState:Dictionary public function beckhoffIO() { // constructor code super(); configureListeners(); } private function configureListeners():void { addEventListener(Event.CLOSE, closeHandler); addEventListener(Event.CONNECT, connectHandler); addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); addEventListener(DataEvent.DATA, socketDataHandler); } private function clean():void { removeEventListener(Event.CLOSE, closeHandler); removeEventListener(Event.CONNECT, connectHandler); removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); removeEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); removeEventListener(DataEvent.DATA, socketDataHandler); } public function writeln(str:String):void { str += "\n"; try { send(str); } catch(e:IOError) { trace(e); } } private function closeHandler(event:Event):void { trace("closeHandler: " + event); } private function connectHandler(event:Event):void { trace("connectHandler: " + event); } private function ioErrorHandler(event:IOErrorEvent):void { trace("ioErrorHandler: " + event); } private function securityErrorHandler(event:SecurityErrorEvent):void { trace("securityErrorHandler: " + event); } private function socketDataHandler(d:DataEvent):void { trace("socketDataHandler: " + d.data); var char:String = d.data; (char == ",") ? parseMessage() : xmlBuffer+=char; } private function parseMessage():void { var mess:String = xmlBuffer; xmlBuffer = new String; //IOEvent } } }