O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

14.13. Seeking Relative to the Total Stream Length

Problem

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

Solution

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

Discussion

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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required