movieclip movement triggered by socket event, need more frequent rendering
sneakyimp May 11, 2009 12:29 PMI have a flash project that's implementing a simple two player game. I have added an enterFrame function to my main movie which listens for keyboard activity in order to move a cowboy gunslinger. Whenever the cowboy moves, I send a message over a socket to a server which dispatches the movement to the other connected client. This works pretty well, however, the movement messages tend to arrive in clumps which results in jumpy animation of my cowboy on my opponents screen and jumpy animation of his cowboy on my screen. To illustrate, i put a trace in my enterFrame function because I am imagining that this function will run roughly once each time my main movie renders the screen. I also put a trace statement in my function that responds to network traffic and moves the remote player's cowboy on my screen. Here's the output:
enter frame:4 enter frame:4 enter frame:4 client movePlayer running client movePlayer running client movePlayer running client movePlayer running client movePlayer running enter frame:4 enter frame:4 enter frame:4 enter frame:4 enter frame:4 enter frame:4 client movePlayer running client movePlayer running client movePlayer running client movePlayer running client movePlayer running client movePlayer running enter frame:4 enter frame:4 enter frame:4 enter frame:4
As you can see, I'll get several messages in a row from the remote client which instruct me to move their cowboy ('client MovePlayer running') and they will all run in a row before the screen updates.
I'm guessing I should be using something like updateAfterEvent but this method is only provided by Mouse, Timer, and Keyboard events.
So a few questions:
1) Can someone recommend a good approach to force a screen render each time an incoming movePlayer event arrives over the socket? It's important to note that my function for handling these events has no visibility to the original socket data event.
2) Am I right in understanding that the enterFrame function of my main movie happens once each time my movie is rendered? Is there some more accurate event to which I could attach a trace message so that I better understand the relative frequency of the render events and the socket events?
3) Does firing an updateAfterEvent call force onEnterFrame events to happen more frequently? I'm worried about destroying performance by inadvertently firing more enterFrames which would fire more socket events which would fire more enterFrames, etc., etc.
Any help would be much appreciated.


