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);
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access