O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

13.16. Program: A Sound Controller Component

This example program implements a sound controller component that creates a controller for the playback of sounds. The entire component is created using ActionScript, including the drawing of the buttons and sliders.

In this example, you’ll learn how to create, package, install, and use the component.

To create the component, do the following:

  1. Open a new Flash document and save it as Sound Controller.fla. Normally, it is not good practice to include spaces in the names of your Flash documents. However, components that are installed using the Extensions Manager show up in the Components panel under a menu selection with the same name as the .fla from which the components were installed. So we want to use a readable, user-friendly name.

  2. Create a new movie clip symbol named Slider. This movie clip will be a component used by the sound controller component. It creates a slider controller.

  3. Although it is usually considered a best practice not to attach code directly to a symbol, creating a reusable component mandates an exception to the rule. Therefore, attach the following code directly to the first frame of the Slider symbol:

    #initclip
    
    // Include the .as files for getNewDepth(  ), drawRectangle(  ), and drawCircle(  ).
    // MoveClip.as is from Chapter 7, and DrawingMethods.as is from Chapter 4. #include "MovieClip.as" #include "DrawingMethods.as" // The constructor does not need to do anything, but it does need to exist. function SliderClass( ) {} ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required