views:

31

answers:

1

Hi, 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); 
  }      
        }
    }
A: 
package
{   import com.adobe.serialization.json.JSON;

import flash.display.Sprite;
import flash.errors.*;
import flash.events.*;
import flash.net.Socket;
import flash.text.TextField;
import mx.rpc.events.ResultEvent;


    public class deneme2 extends Sprite
    {    
        private var newText:TextField=new TextField();
        private var listText:TextField=new TextField();
        private var magnetic:Socket=new Socket("localhost",5331);
        private var MNx:Number;
        private var MNy:Number;
        private var MNz:Number;
        private var d:Object={"x":null, "y":null, "z":null};


        public function deneme2()
        {

            magnetic.addEventListener(ProgressEvent.SOCKET_DATA,getDATA); 

        }

        private function getDATA(event:ProgressEvent):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="X="+String(MNx)+" Y="+String(MNy)+" Z="+String(MNz);

            addChild(listText);
        }
    }


}
asilloo