User Guide

408 Networking and Communication
Displaying messages from the socket server
Whenever a message is received from the socket server, or an event occurs, the custom msg()
method is called. This method appends a string to the TextArea on the Stage and calls a
custom
setScroll() method, which causes the TextArea component to scroll to the very
bottom. The
msg() method is as follows:
private function msg(value:String):void
{
ta.text += value;
setScroll();
}
If you didnt automatically scroll the contents of the TextArea component, users would need
to manually drag the scroll bars on the text area to see the latest response from the server.
Scrolling a TextArea component
The setScroll() method contains a single line of ActionScript that scrolls the TextArea
component’s contents vertically so the user can see the last line of the returned text. The
following snippet shows the
setScroll() method:
public function setScroll():void
{
ta.verticalScrollPosition = ta.maxVerticalScrollPosition;
}
This method sets the verticalScrollPosition property, which is the line number of the
top row of characters that is currently displayed, and sets it to the value of the
maxVerticalScrollPosition property.
Example: Uploading and downloading
files
The FileIO example demonstrates techniques for perform file downloading and uploading in
Flash Player. These techniques are:
Downloading files to a users computer
Uploading files from a user’s computer to a server
Cancelling a download in progress
Cancelling an upload in progress