{"id":3403,"date":"2014-03-24T01:26:48","date_gmt":"2014-03-24T01:26:48","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/24\/read-string-sent-to-socket-from-irc-python-script-in-actionscript-3-flash-collection-of-common-programming-errors\/"},"modified":"2014-03-24T01:26:48","modified_gmt":"2014-03-24T01:26:48","slug":"read-string-sent-to-socket-from-irc-python-script-in-actionscript-3-flash-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/24\/read-string-sent-to-socket-from-irc-python-script-in-actionscript-3-flash-collection-of-common-programming-errors\/","title":{"rendered":"Read string sent to socket from IRC python script in Actionscript 3 Flash-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to find a simple way to read text strings sent from a python script running on an IRC client into my Adobe Flash document so I can choose how they are displayed within the flash.<\/p>\n<p>I have had help from Mrs to create the following AS3 code, but I get the following error :<\/p>\n<p>An error occurred: [IOErrorEvent type=&#8221;ioError&#8221; bubbles=false cancelable=false eventPhase=2 text=&#8221;Error #2031: Socket Error. URL: 127.0.0.1&#8243;]<\/p>\n<p>Document Class for my flash file (loaded first in flash document):<\/p>\n<pre><code>package\n{\n    import Mrs.SocketMessageEvent;\n    import Mrs.SocketTest;\n\n    import flash.display.Sprite;\n    import flash.system.Security;\n\n    public class Temp_Example2 extends Sprite\n    {\n        protected var socket:SocketTest;\n        public function Temp_Example2()\n        {\n            this.socket = new SocketTest();\n            this.socket.addEventListener(SocketMessageEvent.MESSAGE_RECEIVED, onSocketMessage);\n            flash.system.Security.allowDomain(\"*\");\n            flash.system.Security.allowInsecureDomain(\"*\");\n            this.socket.connect(\"127.0.0.1\", 7001);\n        }\n\n        protected function onSocketMessage(e:SocketMessageEvent):void \n        {\n            var date:Date = new Date();\n            trace(date.hoursUTC + \":\" + date.minutesUTC + \":\" + date.secondsUTC + \" Incoming message: \" + e.message);\n        }\n    }\n}\n<\/code><\/pre>\n<p>SocketTest Class (In Mrs subfolder):<\/p>\n<pre><code>package Mrs\n{\n    import flash.errors.IOError;\n    import flash.events.Event;\n    import flash.events.IOErrorEvent;\n    import flash.events.ProgressEvent;\n    import flash.events.SecurityErrorEvent;\n    import flash.net.Socket;\n\n    public class SocketTest extends Socket \n    {\n        protected var _message:String;\n\n        public function SocketTest() \n        {\n            super();\n            this._message = \"\";\n\n            this.addEventListener(Event.CONNECT, socketConnected);\n            this.addEventListener(Event.CLOSE, socketClosed);\n            this.addEventListener(ProgressEvent.SOCKET_DATA, socketData);\n            this.addEventListener(IOErrorEvent.IO_ERROR, socketError);\n            this.addEventListener(SecurityErrorEvent.SECURITY_ERROR, socketError);\n        }\n\n        protected function socketData(event:ProgressEvent):void \n        {\n            var str:String = readUTFBytes(bytesAvailable);\n\n            \/\/For this example, look for \\n as a message terminator\n            var messageParts:Array = str.split(\"\\n\");\n\n            \/\/There could be multiple messages or a partial message, \n            \/\/pass on complete messages and buffer any partial\n            for (var i = 0; i &lt; messageParts.length; i++) \n            {\n                this._message += messageParts[i];\n                if (i &lt; messageParts.length - 1) \n                {\n                    this.notifyMessage(this._message);\n                    this._message = \"\";\n                }\n            }\n        }\n\n        protected function notifyMessage(value:String):void \n        {\n            this.dispatchEvent(new SocketMessageEvent(SocketMessageEvent.MESSAGE_RECEIVED, value));\n        }\n\n        protected function socketConnected(event:Event):void \n        {\n            trace(\"Socket connected\");\n        }\n\n        protected function socketClosed(event:Event):void \n        {\n            trace(\"Connection was closed\");\n            \/\/TODO: Reconnect if needed\n        }\n\n        protected function socketError(event:Event):void \n        {\n            trace(\"An error occurred:\", event);\n        }\n    }\n}\n<\/code><\/pre>\n<p>SocketMessageEvent Class (Again in Mrs subfolder):<\/p>\n<pre><code>package Mrs\n{\n    import flash.events.Event;\n\n    public class SocketMessageEvent extends Event\n    {\n        public static const MESSAGE_RECEIVED:String = \"messageReceived\";\n\n        protected var _message:String;\n\n        public function SocketMessageEvent(type:String, message:String = \"\", bubbles:Boolean = false, cancelable:Boolean = false)\n        {\n            super(type, bubbles, cancelable);\n            this._message = message;\n        }\n\n        public function get message():String\n        {\n            return this._message;\n        }\n    }\n}\n<\/code><\/pre>\n<p>I&#8217;ve looked and some people suggested this may be a compile options error but not sure how find the option to change.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to find a simple way to read text strings sent from a python script running on an IRC client into my Adobe Flash document so I can choose how they are displayed within the flash. I have had help from Mrs to create the following AS3 code, but I get the following error [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3403","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3403"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3403\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}