Skip to Content
Actionscript Cookbook
book

Actionscript Cookbook

by Joey Lott
July 2003
Intermediate to advanced
896 pages
45h 43m
English
O'Reilly Media, Inc.
Content preview from Actionscript Cookbook

13.1. Creating an Object to Control Sound

Problem

You want to control sounds at runtime.

Solution

Create a new movie clip to serve as the sound’s target and then pass a reference to that clip to the Sound( ) constructor function (to create a new Sound object). Alternatively, create and invoke a custom createNewSound( ) method that handles this process automatically.

Discussion

Sound objects enable you to load sounds, play sounds, and control the volume and panning of sounds within your Flash movies. A Sound object must target a movie clip (_root is also a valid target). The audio that is controlled must be placed in the movie clip’s timeline at authoring time or loaded into the movie clip at runtime using attachSound( ) or loadSound( ). In any case, it is possible for you to place/load multiple sounds into a single movie clip, but doing so is discouraged. The reason for this is that a Sound object controls the audio in the target movie clip as a whole, so it is not possible to control each of the sounds separately if they are all in the same movie clip. Therefore, it is better to place/load each sound into its own movie clip and create a separate Sound object to control each one.

When you create a new Sound object, specify a target movie clip. To control sounds in the current timeline, specify the keyword this as the target.

// Incorrect. This does not work properly. mySound0_sound = new Sound( ); // Correct. This targets the current timeline. mySound1_sound = new Sound(this); ...
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

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

ActionScript 3.0 Cookbook

ActionScript 3.0 Cookbook

Joey Lott, Darron Schall, Keith Peters
ActionScript 3.0 Design Patterns

ActionScript 3.0 Design Patterns

William Sanders, Chandima Cumaranatunge

Publisher Resources

ISBN: 0596004907Catalog PageErrata