Skip navigation
Currently Being Moderated

Help with ERROR...

Apr 2, 2012 7:54 AM

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

 

 

Flex1.jpg

 

Error 1:

 

Flex2.jpg

 

Error 2:

Flex3.jpg

 
Replies
  • kglad
    72,213 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 2, 2012 8:18 AM   in reply to fsoender

    i don't know if the switch command is different in flex than flash, but that's incorrect syntax for using switch in flash.  look in the api to see the correct way to use switch in flex.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 2, 2012 8:19 AM   in reply to kglad

    switch statements in flex and flash are exactly the same

     
    |
    Mark as:
  • kglad
    72,213 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 2, 2012 8:25 AM   in reply to _spoboyle

    thank you, _sp.

     

    op:

     

    correct use is:

     

    switch(o.command){

    case somevalue:

    //some code

    break;

    case someothervalue:

    //some other code

    break;

    //etc

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 2, 2012 10:05 AM   in reply to fsoender

    -

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 2, 2012 10:08 AM   in reply to fsoender

    Man I hate when these forums won't let you edit. I read the post wrong.

     

    try needs a catch or finally. It needs to know what to "do" when it fails.

     

    e.g.:

     

    try

    {

         // this

    }

    catch (e)

    {

         // error occured, do something if you want

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 2, 2012 12:05 PM   in reply to fsoender

    kglad initially helped you so you should mark him as correct answer and you can just mark mine as helpful.

     

    You should declare them at the top of your class and they all need an access modifier. Such as private, protected, internal, public.

     

    e.g.

     

    package {

     

        import flash.display.Sprite;

     

        public class MyClass extends Sprite {

     

            // define your variables here

             private var NewValue:String;  // create a variable only this class can use by marking it private

     

            // constructor

            public function MyClass() {

                    NewValue = "Some String"; // set the initial value

             }

     

            private function SomeFunction():void

             {

                   // this function is in this class so I can modify NewValue

                    NewValue = "Some Other Value"; // work fine

             }

        }

    }

     
    |
    Mark as:
  • kglad
    72,213 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 2, 2012 12:41 PM   in reply to fsoender

    you can't assign an int cast variable to be an Object cast object.

     

    you should be using something like:

     

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

    switch(o.command){

    case one_of_the_values_that_o.command_can_be:

    // code for this case

    break;

    case another_value_that_o.command_can_be:

    // code for this other case

    break;

    .

    .

    }

     

    if you don't understand how to apply that pseudo code to your situation, paste the possible values of o.command

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 2, 2012 12:46 PM   in reply to fsoender

    Glad you got it working

     
    |
    Mark as:
  • kglad
    72,213 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 3, 2012 11:22 AM   in reply to fsoender

    that continues to make no sense.

     

    there's no reason you should be using a switch statement in that code.  use:

     

    protected function udpDataHandler(event.DatagramSocketDataEvent):void{

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

    if(o.command){

    NewValue=o.command;

    } else {

    NewValue=0;

    }

    }

     

    // and i have no idea what you're doing in timeHandler but myArray must be a very poor choice of names because that can't be an array.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 3, 2012 11:31 AM   in reply to fsoender

    Indeed your switch will only ever do 1 thing so there's no reason to put the switch in there. Unless you plan on eventually doing "different things" if o.command differs, ditch the switch as kglad said.

     

    You're also casting e:Error to the base Error class but there may be a fragment of a chance that whatever is happening may not conform to that. I went with the safest approach and left e untyped (*, or dynamic) so it would catch anything at all if it came in. Try adjusting it back to "catch (e)" instead of "catch (e:Error)". ANEs introduce a new layer of complexity with not everything is predictably going to be an error. For full safety you can even provide a default value, "catch (e = null)" but this is what flash does at the moment anyhow. Down the line if type checking gets stricter you'll get an argument error otherwise.

     

    In timerHandler() you probably should check the value of NewValue. If it equals zero then there's no real reason to push it onto what I assume is a stack you're creating from received UDP packets.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 3, 2012 11:56 AM   in reply to fsoender

    try {} catch() {} has the job of attempting to run code you know may fail. It's a way of gracefully handling problems without your app exiting.

     

    You need to see what is coming in the catch (e). trace(e) and see what you get. There has to be some information in there as to what is going wrong.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 4, 2012 6:44 AM   in reply to fsoender

    From looking at your code most of it looks fine, I have only basic questions. Further, I am as mentioned not familiar with the UDP ANE at all.

     

    One tiny thing is why not run initTimer() from your applicationComplete event? At least you guarantee that udpSocket is created already. So the last line of applicationCompleteHandler() can be initTimer();. Just a small thing to make sure the timer doesn't hit before a socket is made.

     

    Second, as far as I know DatagramSocketDataEvent is part of flash.events (beta in that link at that). Is that really what the UDP ANE is sending back for an event? It could be perfectly fine, I'm just wondering why it doesn't have its own event. Or did they name their version of the event the same thing?

     

    Also have you trace()d what happens on the if (o.command) { trace(o.command); } ? Just to see if anything ever comes in.

     

    Also, in timerHandler(), is it really a good idea to add to myArray if NewValue == 0? Is that 0 useful to you? I presume you're making myArray bindable because whatever graph your using can use the values in it to plot something or such but is 0 useful? To me if it's ever set to 0 then nothing came in over the socket and you shouldn't really do anything, but I don't ultimately understand what you're doing with the socket anyhow.

     

    0 may very well come over the socket so maybe you want to set it to something to flag yourself that nothing came over the socket, like -1. If you ever sense NewValue == -1 then you know to ignore that timer. 

     

    I don't see the graph portion so I presume as mentioned that it's just reading the binded data.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 4, 2012 8:07 AM   in reply to fsoender

    Elaborate more on what you mean by "they don't work together". What exactly isn't working? Not receiving any UDP packets? Graph not reading the binded array?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 4, 2012 9:24 AM   in reply to fsoender

    Haha probably just a bind or invalid type issue.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 4, 2012 11:05 AM   in reply to fsoender

    You made NewValue an object. That means you need to assign a property to it. If you want to read a string, simply convert NewValue to a String instead of an object.

     

    Do one of these two things:

     

    1) Add a property to NewValue if you keep it an object, e.g.

     

    NewValue.value = o.command;

     

    2) Change NewValue to a String

     

    // at the top of the class

    public var NewValue:String;

     

    // assignment, just how you have it now

    NewValue = o.command;

     

    Besides that, you really need to stop adding the switch in there. That switch is absolutely pointless. There is no difference between that switch and this:

     

    if (true) {

         messageArea.appendText(o.command);

         NewValue = o.command;

    }

     

    The code above is pointless. It will happen 100% of the time. So ditch the switch. Just make it:

     

    try

    {

         var o:Object = event.data.readUTFBytes(event.data.bytesAvailable);

        

         if (o.command)

         {

              messageArea.appendText(o.command);

              NewValue = o.command;

         }

         else

         {

              NewValue = ""; // set to empty string (if you change NewValues type to String)

         }

    }

    catch (e)

    {

         event.data.position = 0;

         messageArea.appendText(event.data.readUTFBytes(event.data.bytesAvaila ble));

    }

     

    You can use a switch, but if you only provide a default it will do that every single time. That's why it's 100% useless. You need to provide cases for the switch statement for it to do different things based on what comes in.

     

    e.g.

     

    switch(o.command)

    {

         case "": // contains nothing

              event.data.position = 0;

              messageArea.appendText(event.data.readUTFBytes(event.data.bytesAvaila ble)); // just write out whatever the bytes were (this is kinda useless too)

              break;

     

         default: // it contains SOMETHING, so use it, but containing nothing was handled above

              messageArea.appendText(o.command);

              NewValue = o.command; // assuming this is type String

              break;

             

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 4, 2012 11:16 AM   in reply to fsoender

    Haha yep. Just get that default-only switch statement out of there . It's not doing anything at all.

     

    Glad you got it fixed.

     

    Sorry I don't know the chart components but that should be kept in another thread anyhow. That's more of a flex question.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points