- Creating a Sound Object. - One of the most important points to realize about Sound objects is that you associate each one with a particular timeline in your movie at the time you create the sound. - To dynamically control sound on the root timeline, you would need to create a Sound object and associate it with the root timeline. - To dynamically control sound in a movie clip instance, you would have to create a Sound object associated with that timeline. - understood that when a Sound object is created and associated with a particular timeline, all sounds in that timeline will be controlled equally using that single Sound object.. - Setting the volume of that timeline's Sound object to 50 will relatively decrease all sounds on all layers of that timeline by 50 percent.. - var soundObjectName:Sound = new Sound (Target);. - soundObjectName denotes the name of your new Sound object. - just make sure the name describes the sounds that it controls and that you follow the same rules for naming your Sound object as you would for naming variables: no spaces, punctuation marks, or numbers as the first character of the name.. - The syntax new Sound is ActionScript's way of creating a new Sound object.. - (Target) is where you indicate to the timeline which target path will be associated with this Sound object.. - (for example, volume and panning) by referencing in your scripts the name of the Sound object, not the target path or instance name of the timeline.. - To create a Sound object to control the sound in a movie clip instance named myMovieClip_mc, you would use the following syntax:. - var mySound:Sound= new Sound ("myMovieClip_mc");. - After you've created a Sound object associated with the movie clip instance myMovieClip_mc, you would use the setVolume() method of the Sound class to dynamically adjust the volume to 50 percent, as the following syntax shows:. - In the exercise that follows, we'll create a Sound object—the first step in producing that bouncing ball.. - o The Ball layer contains the basketball graphic, which is a movie clip instance appropriately named basketball_mc. - o The Ball Score layer contains a movie clip named score_mc (placed in front of the goal) that will be used to simulate the ball swishing into the goal.. - o The Watermark layer contains a see-through graphic that appears on the lower-right portion of the stage, simply to give our project a realistic. - o The Actions layer will contain most of the scripts for this project.. - Double-click the basketball_mc movie clip instance to open its timeline.. - This movie clip contains three layers: Shadow, Graphic, and Sound. - Because the movie clip's timeline doesn't include a stop() action, playback will continue to loop, giving the effect of a continuously bouncing ball.. - Now it's time to create a Sound object associated with the basketball_mc movie clip instance. - This object will allow us to control the volume and panning of the bounce sound as the user drags the ball around the court.. - With the Actions panel open, select Frame 1 of the Actions layer and add the following script:. - var bounce:Sound = new Sound(basketball_mc);. - The only function of this line of script is to create a new Sound object named bounce that's associated with the basketball_mc timeline. - Because the bouncing sound is part of this timeline, we'll be able to dynamically control the volume and panning of that sound by controlling the bounce Sound object.. - The important point to realize is that as soon as the movie begins to play, a Sound object is created. - The bounce inside the basketball_mc instance won't sound different until we modify our new Sound object.
Xem thử không khả dụng, vui lòng xem tại trang nguồn hoặc xem
Tóm tắt