2 Replies Latest reply: Apr 2, 2012 8:13 AM by PierreSolutions RSS

    Problem with code

    fsoender Community Member

      Im new to Flex, and I got some problem with this code.

       

      The problem is the "NewValue" I want to be updated thru UDP, any help?

       

       

       

       

      <fx:Script>

                    <![CDATA[           

                                       

                    import be.aboutme.nativeExtensions.udp.UDPSocket;            

                    import flash.events.TimerEvent;

                    import flash.utils.Timer;        

                    import mx.collections.ArrayCollection;

                    import mx.events.FlexEvent;      

                    private var udpSocket:UDPSocket;

                          

                   

                           protected function applicationCompleteHandler(event:FlexEvent):void

                           {

                                 udpSocket = new UDPSocket();

                                 udpSocket.addEventListener(DatagramSocketDataEvent.DATA, udpDataHandler);

                                 udpSocket.bind(1000);

                                 udpSocket.receive();

                           }

                          

                           protected function udpDataHandler(event:DatagramSocketDataEvent):void

                           {

                                 try

                                 {

                                        var o:Object = event.data.readObject();

                                        switch(o.command)

                                              var NewValue = new o:Object;   <---------- HERE!  

                                 }

                           }

                          

                   

                    [Bindable]

                    public var myArray:ArrayCollection = new ArrayCollection();

                    public function initTimer():void

                    {

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

                           myTimer.addEventListener("timer", timerHandler);

                           myTimer.start();

                    }

                   

                    public function timerHandler(event:TimerEvent):void

                    {

                           var obj:Object = new Object();

                           var NewValue;

                           obj.time = getTimer();

                           obj.Value = NewValue;   <---------- HERE!

                           myArray.addItem(obj);

                          

                    }

                    ]]>

             </fx:Script>

       

        • 1. Re: Problem with code
          fsoender Community Member

          I get these two errors, can anyone help me out?

           

           

          Flex1.jpg

           

          Error 1:

           

          Flex2.jpg

           

          Error 2:

          Flex3.jpg

          • 2. Re: Problem with code
            PierreSolutions Community Member

            Your syntax looks funny to me.

            I am not familiar with that approach.

            Following are some suggestions.

             

            try something like

            var o:Object = event.data.readObject();

            var NewValue = o;

             

            or if you are trying to typecast then

            var NewValue = o as Object;

            or

            var NewValue = Object(o);

             

            also it looks like you are missing the 'catch' part of the 'try / catch' structure.

             

            try

            {

                 ... some code here

            }

            catch (err:Error)

            {

                 ... handle error here if it happens

            }

             

            I hope this helps you a bit.