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:
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 customgetStreamLength( )
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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.