At the beginning of this chapter, we learned that ActionScript provides two different mechanisms for adding an external display asset to an application at runtime:
The flash.display.Loader class
The flash.net.Socket class, used in combination with the Loader class's instance method loadBytes( )
Now that we're comfortable with the Loader class, let's examine how it can be combined with the Socket class to retrieve display assets over a raw TCP/IP socket. The technique described in this section might be used when loading assets for a socket-based application such as a multiuser game, or simply to prevent the loaded asset from appearing in the end user's cache.
Here's the general process for retrieving display assets over a raw TCP/IP socket:
Connect to a server that can transfer a GIF, PNG, JPEG, or SWF file in binary format to the Flash runtime.
Retrieve the bytes for the desired asset.
Convert the loaded bytes to an asset object, suitable for on-screen display.
To accomplish the first two of the preceding steps, we use ActionScript's flash.net.Socket class. The Socket class communicates with a server in binary data format (in raw bytes). To accomplish the final step, we use the Loader class's instance method loadBytes( ) method. The loadBytes( ) method converts raw bytes to an ActionScript display object.
The following sections describe the preceding process in detail.
Using the Socket class, we can retrieve the ...