Flash 5 offers many new object types, and one of the most exciting objects to use is the Sound Object. Like most objects, the Sound Object has predefined methods that you can use to control each new Sound Object. Table below provides an overview of the Sound Object and its methods. Reasons for using Sound Objects over traditional Sound Movie Clips or keyframe sounds:
Unlike the Color Object that uses Movie Clips as targets, the Sound Object uses sounds directly from the movie’s Library. You cannot use the Sound Object to control sounds that are specified in the Sound Panel for any given keyframes. The next section shows you how to create Sound Objects, using the object constructor with the attachSound and start methods.
Methods for the sound object
Creating sound libraries with ActionScript
You learned how to create a sound library Movie Clip that stored several individual sound Movie Clip instances. You learned how to target these sounds in order to play them (or mute them). From a conceptual point of view, manually creating each sound Movie Clip enabled you to see each sound “object” on the Stage very easily. However, we can produce the sounds for a sound library much more quickly using ActionScript.
You can also open the pianoKeys_complete.fla file.
The attachSound method can only use sounds that have been set to export with the Flash .SWF file.
These first lines establish the name of our function, createLib. We will want to dynamically change the number of sounds we create with this function. Therefore, we assign an optional parameter (called an argument) num that will be passed to the nested actions within the function. The second line starts a for loop that cycles its nested actions until the condition i<=num is no longer true. i starts (or initializes) with a value of 1, and the syntax i++ tells i to increase by 1 with each pass of the for loop. In the next step, we want the for loop to (a) create an array to store a reference to each sound instance; (b) create a new instance of the Sound Object for each sound in the Library; and (c) attach each sound in the Library to its new instance.
The first line of code in Step 7 checks whether i’s current value is 1. During the first pass in the for loop, this will be true. So, the contents of the if nest will be executed. The second line of code occurs within the if nest. This line creates a new Array named snd and is made a property of this. this refers to the object that targets (or evokes) the createLib function. Because we’re only defining our function, we haven’t made this function a target for any Movie Clip instance. This line will only be executed once, while the value of i is 1. When i’s value increases in subsequent passes of the for loop, this line will be ignored.
The third line executes a trace action, which sends alert messages to the Output window (in the Test Movie environment). The trace action in the third line will tell us that the actions in the if nest have been executed by sending new Array created to the Output window. The fourth line is also a trace action that tells us what object is evoking (or executing) the createLib function.
The fifth line makes a new element in the snd array. The new element is a new Sound Object that is targeted at the this timeline. Ultimately, our Sound Objects will be tied to the soundLib Movie Clip instance, which you’ll see later. Each element in an array has a number indicating its position in the array. Because the value of i increases with each pass of the for loop, each Sound Object will have a unique position within the snd array.
The sixth line uses the attachSound method to take a sound element in the Library and attach it to the Sound Object in the snd array. The target for the attachSound method is specified as “sound_” + i. On each pass of the for loop, this expression will return “sound_1”, “sound_2”, and so on until our limit prescribed by the num argument is reached. The complete block of code on the first keyframe of the actions layer should look like this:
The first line of code defines a method called createLib that used the function createLib as a value. Because createLib is a function, the createLib method of soundLib will execute the createLib function whenever the method is evoked.
The second line of code evokes the createLib method—the use of () after the method name indicates that the method is being executed, not defined. In addition to executing the createLib method, we’re also sending the function the number 7 as the num argument. Therefore, seven Sound Objects will be created.
The first line of code targets the first declared element, 1, of the snd array, and tells it to begin playback with the start method. Remember that element 1 in the array is a Sound Object, which references the sound_1 ID in the Library. The second line of code targets the second declared element, 2, of the snd array, and tells it to start.
So, you will hear sound_1 (which is key_1.aif or key_1.wav) and sound_2 (key_2. aif or key_2.wav) play together. Now you should practice targeting these Sound Objects with Button instances and other keyframes. To access a different sound, simply change the number in the array brackets. The next tutorial introduces the pan methods of the Sound Object, and shows you how to use Sound Objects with interactive projects.
Creating a soundTransformObject
The two remaining methods of the Sound Object, setTransform and getTransform, work in the same manner as the transform methods of the Color Object. You need to create a generic object using the object constructor before the setTransform method can be used with a Sound Object. This generic object will become a sound TransformObject once we have assigned sound channel properties to the generic Object.
Luckily, the soundTransformObject doesn’t have as many properties as the colorTransformObject, and they’re much simpler to predict with trial and error testing. The properties of the soundTransformObject are:
The first letter of each property determines which physical speaker is being affected. The second letter determines which channel’s output (or its volume) is played in that speaker. Each property can have a value between –100 and 100. The steps to produce and incorporate a soundTransformObject are nearly the same as the colorTransformObject. The only difference is that you specify paths to Sound Objects rather than Movie Clip Objects for the setTransform and get Transform methods.
Flash Related Interview Questions
|Adv Java Interview Questions||J2EE Interview Questions|
|Adobe Flex 3 Interview Questions||Dreamweaver Interview Questions|
|3D Animation Interview Questions||Adobe Flash CS6 Interview Questions|
|Dreamweaver CS3 Interview Questions||Adobe Flex Interview Questions|
|Adobe Flex Actionscript Interview Questions||Gif Animation Interview Questions|
|Adobe Fireworks Interview Questions|
Understanding The Flash Framework
Exploring The Interface: Panels, Settings, And More
Using Tools For Navigation And Viewing
Working With Selections And The Pen Tool
Working With The Drawing And Painting Tools
Working With Text
Exploring The Timeline
Checking Out The Library: Symbols And Instances
Drawing In Flash
Animating In Flash
Using Bitmaps And Other Media With Flash
Designing Interfaces And Interface Elements
Understanding Sound For Flash
Importing And Editing Sounds In Flash
Optimizing Flash Sound For Export
Understanding Actions And Event Handlers
Navigating Flash Timelines
Controlling Movie Clips
Sharing And Loading Assets
Planning Code Structures
Creating Subroutines And Manipulating Data
Understanding Movie Clips As Complex Objects
Sending Data In And Out Of Flash
Understanding Html And Text Field Functions In Flash
What Is Generator?
Revving Up Generator
Working With Third-party, Server-side Applications
Working With Raster Graphics
Working With Vector Graphics
Working With Audio Applications
Working With 3d Graphics
Working With Quicktime
Working With Realplayer
Creating Full-motion Video With Flash
Creating Cartoon Animation With Flash
Planning Flash Production With Flowcharting Software
Working With Authoring Applications
Publishing Flash Movies
Integrating Flash Content With Html
Using Players, Projectors, And Screensaver Utilities
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.