AS3 通過 TCP/IP 協議控制WatchOut播放
阿新 • • 發佈:2019-01-07
以下為關鍵程式碼
btn1.addEventListener(MouseEvent.CLICK, btnClick); btn2.addEventListener(MouseEvent.CLICK, btnClick); btn3.addEventListener(MouseEvent.CLICK, btnClick); function btnClick(e):void{ var ns:String = e.target.name; switch(ns){ case "btn1": sendMode("part1"); break; case "btn2": sendMode("part2"); break; case "btn3": //sendMode("part3"); //sendMode("gotoControlCue SCREEN_SAVER"); sendMode("gotoControlCue f1"); sendMode("run"); break; } } /*function sendMode(str:String):void{ var bytes:ByteArray = new ByteArray(); bytes.writeUTFBytes(str); socket.writeBytes(bytes); socket.flush(); }*/ function sendMode(_message:String) { if(socket.connected){ try{ var ba:ByteArray = new ByteArray(); ba.writeMultiByte(_message+"\n", "utf-8"); socket.writeBytes(ba); socket.flush(); } catch (e:Error) { //LastErrorMessage = ; trace("Failed to send message"); //this.dispatchEvent(new Event("ERROR")); } trace("Send:", _message); }else { //LastErrorMessage = "Please connect the socket before sending message"; //trace(LastErrorMessage); //this.dispatchEvent(new Event("ERROR")); } }