First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Tim Murray | Website: http://www.gmg.com.au

Part 3: Using the media player

Our approach to using the media controls is simple:

  1. Create a new Flash MX file for the sound.
  2. Import the sound to a layer and give it enough frames to fully play when streaming.
  3. Create a progress animation (if you want to).
  4. Drag our controller to a layer.
  5. Save and publish the sound SWF file.
  6. Create a new main Flash MX file for loading the sound SWF file.
  7. Add the graphics you want and a bit of code to load the sound SWF file.
  8. Save and publish the main SWF file.

I'm not going to go through steps 1, 2, and 3 in detail 'cos it's exactly the same as the stuff we did earlier in this tutorial. See sections "Start with some easy audio", "Putting the sound on the stage", and "Adding a sample graphic" for the specifics. Here's a quick recap of that material:

  1. Create a new Flash MX file for the sound (this time name it "sound.fla") and save it.
  2. Find a sound that you want to share with the world.
  3. Import the sound to a layer named "media".
  4. Make sure it is set to Sync: Stream.
  5. Insert enough frames to stream and play the sound fully.
  6. Create a progress animation that plays across the full extent of the sound.

For longer sound files, we found that the waveforms looked too complicated to be meaningful, so we replaced them with a couple of simple microphone images (one in colour and the other in duotone), and then tweened them like this:

That's it for the quick revision on how to prepare the sound with the animation. Now we're going to add the media controller.

Open your Library (F11) and add a folder named "utilities". This folder will keep any bits and pieces that we add to the file. It's always a good idea to keep your library organised on larger projects.

Make sure that your media-controller.fla file is open and that the Library for it is also open. Now drag the media-controller movie clip from the media-controller.fla file and drop it into the utilities folder in the sound.fla file.

That makes the sound.fla file go looking for the media-controls movie clip in the media-controller.swf file when it needs to use it. Close the Library for the media-controller.fla file.

Go back to the sound.fla file and create a new layer at the bottom of the layers and name it "controller". Select the controller layer. Drag the media-controls movie clip on to the stage. Position it to your liking. We also reduced the size of the stage so that our sound animation and controller just fit on it.

Save the sound.fla file and test it (Ctrl+Enter). You will find that you have a fully functioning audio player. Testing will also create the SWF file (sound.swf) for us.

Finally, we are going to build a main Flash MX file to host our sound file. When we split our Flash sounds into a main file, a sound file, and a controller file, we get several benefits:

  1. The controller is downloaded once for any amount of media that needs a controller.
  2. Our sound file is downloaded separately allowing us to accurately track its download progress and the controller may assume that the sound streams from the first frame to the last frame.
  3. Our main file can still stream graphics and text without having to worry about the sound and its controls.

Create a new Flash MX file and save it as "test-audio.fla". The only important thing to do to the file is add an empty movie clip that you can load the sound.swf movie into and a bit of code to do the loading.

Use the "Insert > New Symbol..." command (Ctrl+F8) to create a new movie clip resource. Name it "movie-container". Create a new layer named "audio" and drag the container movie clip on to the stage where you would like your sound animation and controller to be loaded. Make sure that your movie-container movie clip has an Instance Name of "container" so that we may refer to it easily with ActionScript.

Now add an actions layer for the code to load our sound.swf file. This is the code to do it:


We also added some text and colour to finish things off.

That's it! Save and publish. Nothing more to do (unless you would like to test it).

» Level Advanced

Added: 2004-02-17
Rating: 7.89 Votes: 64
(10 being the highest)
» Author
Tim is a co-director of the Glasson Murray Group, providing quality graphic design, illustration, 3D visualisation, interactive environments, virtual reality, multimedia and website services.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.