通过 JSON 建立 Arduino 和 Flex 4.0 之间的连接
我尝试在 arduino 和 Flex 4.0 之间建立连接,我将 JSON 库和 as3corelib.swc 添加到 Flex 中。当我运行 Flex 文件时,PC 与 arduino 之间的连接正在工作(我可以在 SERPROXY 窗口中看到它),并且在 Flex 窗口中也没有任何问题,我将 Flex 的 SWF 文件添加到 //http 的列表中://www.macromedia.com/support/documentation/tr/flashplayer/help/settings_manager04.html,但是读取结果没有显示在SWF中,我不明白为什么!,感谢您的帮助
,这里是代码
package
{
import com.adobe.serialization.json.JSON;
//http://www.macromedia.com/support/documentation/tr/flashplayer/help/settings_manager04.html
import flash.display.Sprite;
import flash.errors.*;
import flash.events.*;
import flash.net.Socket;
import flash.text.TextField;
public class deneme extends Sprite
{
private var magnetic:Socket=new Socket("localhost",5331);
private var magneticValue:Number=0;
private var distance:Number;
private var newText:TextField=new TextField();
private var listText:TextField=new TextField();
private var MNx:Number;
private var MNy:Number;
private var MNz:Number;
private var d:Object={"x":null, "y":null, "z":null};
public function deneme()
{
socketDataHandler();
}
private function socketDataHandler():void
{
newText.text=magnetic.readUTFBytes(magnetic.bytesAvailable);
d= JSON.decode(newText.text);
MNx=d["x"];
MNy=d["y"];
MNz=d["z"];
listText.x=10;
listText.y=10;
listText.width=600;
listText.height=100;
listText.text=newText.text;
addChild(newText);
}
}
}
I try to make a connection between arduino and Flex 4.0, I added the JSON lib and also as3corelib.swc to Flex. When I run the Flex file the connection between PC to arduino is working (I can see it in SERPROXY window) and also I don't have any problems in Flex window, I added the SWF file of Flex to the list at //http://www.macromedia.com/support/documentation/tr/flashplayer/help/settings_manager04.html, Bu the reading result is not shows in the SWF, I couldn't understand why !, thanks for help
and here the code
package
{
import com.adobe.serialization.json.JSON;
//http://www.macromedia.com/support/documentation/tr/flashplayer/help/settings_manager04.html
import flash.display.Sprite;
import flash.errors.*;
import flash.events.*;
import flash.net.Socket;
import flash.text.TextField;
public class deneme extends Sprite
{
private var magnetic:Socket=new Socket("localhost",5331);
private var magneticValue:Number=0;
private var distance:Number;
private var newText:TextField=new TextField();
private var listText:TextField=new TextField();
private var MNx:Number;
private var MNy:Number;
private var MNz:Number;
private var d:Object={"x":null, "y":null, "z":null};
public function deneme()
{
socketDataHandler();
}
private function socketDataHandler():void
{
newText.text=magnetic.readUTFBytes(magnetic.bytesAvailable);
d= JSON.decode(newText.text);
MNx=d["x"];
MNy=d["y"];
MNz=d["z"];
listText.x=10;
listText.y=10;
listText.width=600;
listText.height=100;
listText.text=newText.text;
addChild(newText);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)