Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 380

Programming actionscript 3.0
Table of Contents

Advertisement

There are three ways to add callback methods to your LocalConnection objects:
Subclass the LocalConnection class and add methods.
Set the
LocalConnection.client
Create a dynamic class that extends LocalConnection and dynamically attach methods.
The first way to add callback methods is to extend the LocalConnection class. You define the
methods within the custom class instead of dynamically adding them to the LocalConnection
instance. This approach is demonstrated in the following code:
package
{
import flash.net.LocalConnection;
public class CustomLocalConnection extends LocalConnection
{
public function CustomLocalConnection(connectionName:String)
{
try
{
connect(connectionName);
}
catch (error:ArgumentError)
{
// server already created/connected
}
}
public function onMethod(timeString:String):void
{
trace("onMethod called at: " + timeString);
}
}
}
In order to create a new instance of the DynamicLocalConnection class, you can use the
following code:
var serverLC:CustomLocalConnection;
serverLC = new CustomLocalConnection("serverName");
The second way to add callback methods is to use the
This involves creating a custom class and assigning a new instance to the
the following code shows:
var lc:LocalConnection = new LocalConnection();
lc.client = new CustomClient();
380
Networking and Communication
property to an object that implements the methods.
LocalConnection.client
property.
property, as
client

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents