I made a controller with 12 buttons, and when each button is pressed its send a string over to actionscript.
The strings that i send are "A1","A2" and so on.
But sometimes the string i receive is "2" instead of "A2".
How can i fix this, because this is very annoying because sometimes the action trigged by the button never fires because of the incomplete string.
private function socketDataHandler(event:Event):void{
var socket:Socket = event.currentTarget as Socket;
var data:String = socket.readUTFBytes(socket.bytesAvailable);
trace(data);
playSoundArduino(data);
}
I suspect the problem is that on the actionscript side you are reading all available bytes from the serial stream and assuming you have got a complete message, but you may only have received a partial message. It would be better to have the actionscript code explicitly determine the end of each message, for example by putting a newline separator between messages and having the actionscript detect that to know that it has received a complete message.
I share PeterH's view. You should use arduino serial monitor to confirm that all button pushes generate complete messages they intend to generate. If you can confirm it, then the problem resides with actionscript. I don't think the delay and max baud rate suggestions are relevant to your problem, especially not knowing what this button.h is.
I agree with Zoomkat, when your writing to a string, as so (globalString += inputOfArduino;), you write to it, make it do it's job, then you have to clear it.
If you don't clear it, it will continue to build up and slow down the processor. I learned this the hard way, with my project.
adding this "globalString = "";" after "globalString = globalString.substr(2);" should eliminate any problems with the string.
Fellows, I think you may have the String thing mixed up. The OP is only using String in actionscript. Isn't that run on a computer instead of on Arduino? 8)
Regarding memory leak, I heard from experts that is a problem with free(). HazardsMind, you may not have experienced a problem possibly because you are not defining String in subroutines or loop (did you just define String outside functions?). There are plenty of others that did get into trouble and fixed the problem by not using String. The problem is if you have a String in functionX then every time the function quits free() should clean up the String but it doesn't, that's what I heard.