14.13. Seeking Relative to the Total Stream Length


You want to seek a stream based on the total length of the stream.


Get the stream length from the server and then use the seek( ) method.


A problem arises when you want to seek within a stream relative to the total length of the stream. For example, if you want to create a slider that a user can move to seek through a stream, you must determine the total length of a stream. There is no client-side property or method that returns that information. However, you can write a server-side function to return a stream’s length using the Stream.length( ) method. Here are the steps to return a stream’s length from the server:

  1. In the server-side .asc file (either the main.asc file or another .asc file that is loaded by main.asc) create a method for client objects that takes the name of a stream and returns the length of that stream (see Recipe 14.4). Most often, you assign methods to a client in the application.onConnect( ) method.

    // The application.onConnect(  ) method is invoked automatically whenever a new
    // client connects to the FlashCom application. The client object is created and
    // passed as a parameter to the method.
    application.onConnect = function (newClient) {
      // Create a custom getStreamLength(  ) method for each client. The method takes // the name of a stream as a parameter. newClient.getStreamLength = function (streamName) { // Return the length of the requested stream. return Stream.length(streamName); ...

Get Actionscript Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.