function onClickBtn2(e:MouseEvent):void{ var data:String = command_2; var bytes:ByteArray = tenToHexFunc(data); udp.send(bytes, 0, 0, this.remoteAddress, this.remotePort); } //将16进制字符串转化为byteArray function tenToHexFunc(_info:String):ByteArray{ _info=_info.split(" ").join("");//删除所有的空格 var byte:ByteArray = new ByteArray(); for (var i:uint = 0; i < _info.length; i = i + 2) { //trace(i); byte.writeByte(uint("0x" + _info.substr(i, 2))) trace(_info.substr(i, 2)); } return byte; } function sendHEXFunc(socket:Socket, msg:ByteArray):void{ socket.writeBytes(msg); socket.flush(); }
http://www.11ria.com/forum.php?mod=viewthread&tid=154&page=4#pid32389