Topics:
- Final Project concept presentations
- Using Audio
- Drag and Drop Events
- Final Project Requirements
- Creating a Project Brief and Sitemap
Using Audio
There are a number of different ways you can play audio through Flash, each has it’s advantages and disadvantages.
Supported Audio types
Many audio types are supported in Flash, but you’ll have best luck with .aiff or .mp3 files. All audio is published out of Flash in the mp3 format, so this is a good format to start with.
Import to Library
You add audio to your Flash movie the same way you import other media assets. You can use either “Import to Library” or “Import to Stage” but either way the audio file will end up in your library, but not on the stage.
Select an imported audio file in the library, and you will see a visual representation of the sound file, in addition to tiny little play and stop buttons to the top and right that allow you to preview the audio file.

To see additional properties of the sound file, double-click the speaker icon next to the filename.

Check your file size! This is going to impact the total size of your swf. You can adjust the compression settings here for this file only or in the Publish Settings panel for the whole movie.
Adding Audio to the Timeline
You add audio to a keyframe on the timeline, in the properties panel when you have a frame selected. The audio will start playing when the swf hits that frame.
Choose the sound you want to add with the “Name” pulldown in the sound section of the properties panel.
Once you do this, you will see the waveform of the sound in the timeline.
Increase the height of the layer by control or right clicking the layer name and changing the layer height:
How the file will playback depends on how the Sync property is set. There are two primary settings you should concern yourself with here:
Event – Plays whole audio file. If you don’t want this, you can do some minor editing in the sound properties. This should be reserved for very short sounds, or you will get awkward echoing as the movie loops and continues to play the sound again and again.
Stream – Plays the sound only as long as the timeline. You can set the repeat and loop settings for replay, but this will always stop a previously playing sound before starting the next one.
The problem with both of these methods is that you aren’t giving the user any control over the playback of the sound. I generally avoid timeline sound in favor of one of the methods below.
Playing Audio from the Library
In order to play an audio file from the library, you have to give it a class name. Control or right click on the file name in the library and open the file properties. On the sound properties panel, click the “Advanced” Button in the bottom right of the panel. In the section that opens up, click the “Export for Actionscript” and “Export in Frame 1″ boxes, and give the file a class name. The name of the audio file will automatically get filled in, but you should change this, having the extension in the name will cause problems.

Now you must create a new instance of this sound in your code, using the class name that you set above:
var track:myTrack = new myTrack();
This won’t automatically start the sound playing, however, you have to tell it to play:
track.play();
If you want to stop the sound, things become a little more complicated, as the stop method is actually part of a different object – the SoundChannel class. So you’ll need an instance of this, and you will need to assign that channel to the playback of your file:
var channel:SoundChannel = new SoundChannel( );
channel = track.play();
channel.stop();
This still isn’t the most ideal way to play audio, however, because the audio file becomes part of the .swf and adds to the file size and download time. Any audio file that is more than a few seconds, you should load into the .swf much in the same way that we did with images.
Loading External Audio Files
This works similarly to the library example, except that we load the sound into a blank generic sound object, using the URLRequest object to hold the value of the audio file name:
var track:Sound = new Sound();
var request:URLRequest = new URLRequest(filename.mp3);
track.load(req);
Drag and Drop Events
Any named movieclip instance on the stage can be made “draggable” with the startDrag( ) method.
myObject.startDrag();
Usually this is triggered with an event listener on the MOUSE_DOWN event on the instance. Once startDrag is called, the object will follow the mouse movement. To stop this behavior, you use the stopDrag( ) method, usually implemented on MOUSE_UP.
myObject.stopDrag();
This behavior also has a property associated called dropTarget. The dropTarget is the object that is under the draggable object when the stopDrag method is called. To get the name of the drop target, you must access its name property.
myObject.dropTarget.name;
Final Project Requirements
Your final project should include the following:
- Timeline animation
- Code control of timeline playback
- At least one dynamic text field whose value is changed by code
- At least one input text field
- At least one button that responds to a mouse event
Planning your project
For next week you are going to produce two documents that will help you define your project.
1. Project Brief – This is a text description of your project. It should include the following:
- Overview: A few sentence summary of the project.
- Audience: Who is application for? Include age range, gender, anticipated technical skills, language capability.
- Platform: How do you envision this application being used? Is it part of a larger Web site? A mobile application? Part of an installation?
- Functionality requirements: Describe how the application will operate. How many distinct states or screens or pages will it have? How will a user interact with it?
- Technical requirements: Describe as best you can what code elements will be required for the application.
2. Process Flow – This is a bit like a site map for a Web site. A process flow visualizes the way a user would move through the application from a high level.

Every distinct state or page of the application should be represented by a rectangle, connected by diamond shaped decision points.