我希望有人可以帮我解决我的AS3脚本问题,我是新手,如果有简单的答案就道歉
import flash.net.Socket;
import flash.events.Event;
var mysocket:Socket = new Socket();
mysocket.connect("127.0.0.1",5331);;
mysocket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
var buffer:String = "";
function socketDataHandler(event:ProgressEvent):void
{
var str:String = String(mysocket.readUTFBytes(mysocket.bytesAvailable));
var array:Array = new Array();
buffer += str;
array = buffer.split(",");
var textpwm:Array = new Array;
var textpercentage:Array = new Array;
var textvoltage:Array = new Array;
textpwm.push(array[0]);
textpercentage.push(array[1]);
textvoltage.push(array[2]);
var pwm_a:String;
pwm_a = textpwm.join("");
var percentage_a:String;
percentage_a = textpercentage.join("");
var voltage_a:String;
voltage_a = textvoltage.join("");
pwmbox.text = pwm_a;
percentagebox.text = percentage_a + "%";
voltagebox.text = voltage_a + "V";
trace(textpwm);
}
这是我的AS3脚本中的代码我试图调试代码并发现我的数组
var textpwm:Array = new Array;
var textpercentage:Array = new Array;
var textvoltage:Array = new Array;
总是保持相同的值,即使从我的arduino我的阵列发送新数据,称为" array"确实随着新值的出现而改变,但其他人只是一遍又一遍地保留相同的数据
如果有人可以提供帮助,那就太棒了
谢谢
答案 0 :(得分:0)
“buffer”是一个全局变量(每当你调用buffer + = str;你将在现有数据之后添加一个新数据)所以使用buffer = str;
而不是+ = OR array = str.split(",");
pwmbox.text = array[0] + " V;";