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

13.4. Getting Playback Time

Problem

You want to determine the time of the current playback position of a sound.

Solution

Use the position property. To get the total time of a sound, use the duration property.

Discussion

Flash offers a convenient way to access information about the playback time for a sound. All Sound objects have position and duration properties (both are read-only), which reflect the current playback position and the total duration of a sound. Both values are given in milliseconds.

trace(mySound_sound.position);
trace(mySound_sound.duration);

The position property updates automatically during playback. You can get the percentage that corresponds to the current playback position by dividing position by duration and multiplying the result by 100:

trace(mySound_sound.position/mySound_sound.duration * 100);

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