0 Replies Latest reply on May 23, 2012 8:32 AM by fsoender

    Toggle switch help

    fsoender

      Hi,

       

      Need help with this code, been pullig my hair out...

      I need the toggle switch to turn on and off the UDP transmition.

       

      I tried to use the "myTimer.start();" but didnt work.

       

      Can anyone help?

       

      Code:

       

       

                 public var myArray:ArrayCollection = new ArrayCollection();

                         

                          public function initTimer():void

                          {

                                 var myTimer:Timer = new Timer(1000, 0);

                                 myTimer.addEventListener("timer", timerHandler);

                                 myTimer.start();

                                

                    }

                         

                         

                     public function timerHandler(event:TimerEvent):void

                          {

                                 var obj:Object = new Object();                       

                                 obj.time = getTimer();                        

                                 obj.Value = NewValue;

                                 myArray.addItem(obj);

                                

                                

                                

                          }           

                         

                         

                          protected function applicationCompleteHandler(event:FlexEvent):void

                          {

                                 udpSocket = new UDPSocket();

                                 udpSocket.addEventListener(DatagramSocketDataEvent.DATA, udpDataHandler);

                                 udpSocket.bind(1000);

                                 udpSocket.receive();                          

                                 initTimer();

                          }

                         

                         

                          protected function udpDataHandler(event:DatagramSocketDataEvent):void

                          {

                                

                                 var Value:String = event.data.readUTFBytes(event.data.bytesAvailable);

                                

                                 if(Value)

                                 {

                                       

                                        NewValue = Value;

                                       

                                 }

                                 else

                                 {

                                       

                                        NewValue = 0;

                                       

                                 }

                                

                          }

                         

      protected function ToggleSwitch changeHandler(event:Event):void

                          {

       

                                 // Need code here.

                                

                          }