Flash MX Audio PlayerAn in depth look at building a reusable streaming audio preloader for Flash MX that includes media controls. 01 Introduction Previous << Part 2: Planning our controls / Getting the sound to play, pause and rewind
|
| Layer name | What we use it for |
labels |
Contains a whole bunch of labelled keyframes and nothing else. This makes it easy to see where our labels are and what they are called. |
actions |
ActionScript that needs to be executed as the movie is playing. We don't put any functions in this layer, just code that needs to be executed on a keyframe. |
functions |
This is for ActionScript functions that we call from the actions layer or in event handlers on movie clips or buttons. When we have the majority of code in one place, it makes debugging much easier because it is easy to find the code. |
That's it. Diversion over. Back to our progressBar code.
Our first function will set the size of the progress bar according to the sound download progress. This code needs to go into your newly created "functions" layer:
function setProgressBar() {
var parentLoaded = 170 * _parent._parent._framesloaded / _parent._parent._totalframes;
progressBar._width = parentLoaded;
}
We are setting the _width of the progressBar movie clip to a fraction of the width of our rectangle on the base layer. I made the rectangle 171 wide and indented the progressBar movie clip by 0.5 from the left, so I want the same distance in from the right, giving 171 - 0.5 - 0.5 = 170. The fraction of 170 that we want is given by the usual _framesloaded / _totalframes. No new stuff here! The only tricky thing is that we have to go up far enough so that _framesloaded and _totalframes will refer to the Flash movie that has the sound streaming on the timeline.
The following table shows what code accesses which movie clip:
Variable |
Movie clip |
_framesloaded |
progress-bar |
_parent._framesloaded |
media-controls |
_parent._parent._framesloaded |
Main timeline |
And now back to the progressBar movie clip. This is the code that needs to go on it to call the setProgressBar function:
onClipEvent (enterFrame) {
_parent.setProgressBar();
}
Test this (Ctrl+Enter) with streaming (Ctrl+Enter again). As Flash simulates the download, you should see the grey bar in the black slider background growing until all of your sound has loaded.
Save now.
Next >> Adding a thumb dragger to the slider
01 Introduction
02 What should the media player do? / How should the player be structured? / Useful reading
03 Part 1: Start with some easy audio
04 Putting the sound on the stage / Adding a sample graphic
05 Animating the waveform
06 Part 2: Planning our controls / Getting the sound to play, pause and rewind
07 Adding a load indicator
08 Adding a thumb dragger to the slider
09 Dragger states
10 Limiting the dragger / Setting the sound's playhead position
11 Making the media controls ready for sharing
12 Part 3: Using the media player
13 Anything else? / Conclusion / About the authors / Copyright
© 2003 Glasson Murray Group Pty Ltd (ACN 098 651 542), Western Australia. All rights reserved.