Mountain with antenna

Using the client property to handle callback functions

Here’s something I see people get hung up on when defining functions in client-side ActionScript and calling them from the Server-Side ActionScript Client.call() method.

In ActionScript 2, you define the functions directly on the NetConnection object, like this:

nc = new NetConnection();
nc.onBWDone = function(){
    return true;
};
nc.onBWCheck = function(){
   return 0;
};
nc.connect("rtmp:/clientCall");

In ActionScript 3, you define the functions on an object assigned to the NetConnection.client property, like this:

var clientObj:Object = new Object();
clientObj.onBWDone = onBWDone;
clientObj.onBWCheck = onBWCheck;
nc.client = clientObj;

public function onBWDone(... rest):Boolean {
   return true;
}

public function onBWCheck(... rest):Number {
   return 0;
}

Note:The previous code includes the callback functions expected by the FMS “live” and “vod” applications.

The NetStream class works similarly to the NetConnection class. You can call NetStream.send() to send messages to other connected clients. Those clients need callback functions that handle the messages.

In AS2 you can define functions on a NetStream object and in AS3 you define functions on an object assigned to the NetStream.client property. See NetStream.client and NetStream.send().

There are several ways to handle callback methods–you can use the technique in this post, you can assign the client property to a new class, you can extend the NetStream or NetConnection class, or you can assign the client property to this. For good examples, see “Writing callback methods for metadata and cue points”.

December 3, 2009   No Comments


Warning: main(/home/70767/etc/...) [function.main]: failed to open stream: Permission denied in /nfs/c05/h01/mnt/70767/domains/blog.flashvideoexamples.com/html/wp-content/themes/neoclassical/neoclassical/footer.php on line 10

Warning: main(/home/70767/etc/...) [function.main]: failed to open stream: Permission denied in /nfs/c05/h01/mnt/70767/domains/blog.flashvideoexamples.com/html/wp-content/themes/neoclassical/neoclassical/footer.php on line 10

Warning: main() [function.include]: Failed opening '/home/70767/etc/...' for inclusion (include_path='.:/usr/local/php-4.4.8-1/share/pear') in /nfs/c05/h01/mnt/70767/domains/blog.flashvideoexamples.com/html/wp-content/themes/neoclassical/neoclassical/footer.php on line 10