Socket Progress Events

The flash.net.Socket class has been available to us since the initial release of Adobe AIR. 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 AIR 3, we now have access to the flash.events.OutputProgressEvent class, with which we can easily monitor both the pending and total bytes being sent 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 Adobe AIR 3 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.