Socket Progress Events

The flash.net.Socket class has been around for about 5 years now, beginning with Flash Player 9. When using sockets in ActionScript, developers have always had access to an event to monitor the progress of input data coming through the socket by using flash.events.ProgressEvent. Up until now, however, monitoring the output data being sent across a socket connection has been nearly impossible.

With Flash Player 11, we now have access to the flash.events.OutputProgressEvent class, with which we can easily monitor both the pending and total bytes being send out over a socket connection. This can be used in order to display something like a progress indicator to the user, sequence certain events within an application, or simply verify that the data has been fully processed over the socket.

In the following example, we establish a socket connection and monitor both the flash.events.ProgressEvent and flash.events.OutputProgressEvent events when connected to adobe.com using a basic socket connection.

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.OutputProgressEvent; import flash.events.ProgressEvent; import flash.net.Socket; import flash.text.TextField; import flash.text.TextFormat; import flash.utils.ByteArray; [SWF(width="600", height="500", backgroundColor="#CCCCCC")] public class SocketProgress extends Sprite { private var traceField:TextField; private var socket:Socket; public function SocketProgress() ...

Get What's New in Flash Player 11 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.