web design template web design template web design template

Page : 1 2 3


22. Choose Window > Properties

23. In the Properties panel type the Instance name as 'volume'


1. Choose File > Import to Library

2. Import 2 sounds in formats supported by Flash MX i.e. *.WAV, *.MP3 and *.AIFF. We have imported loopA.wav and loopB.wav sounds which are provided in the source folder.

3. To play these sounds, we are going to use 'attachSound' method in Flash MX.

4. Choose Window > Library

5. In Library select loopA.wav sound and click the top right tab to open the options menu.

6. In the options menu, select 'Linkage...'


7. In the Linkage Properties panel, select 'Export for ActionScript' option. ('Export in first frame' option also gets clicked)

8. In the Identifier textfield type the identifier as 'loop1'


9. Similarly, assign 'loop2' identifier for loopB.wav sound.

10. Insert a new layer above Slider layer and rename it as 'Actions'.

11. Select frame 2 on Actions layer and choose Insert > Keyframe

12. Choose Window > Actions

13. In the Actions panel type the following actions.

snd1 = new Sound();
snd1.attachSound("loop1");
snd1.start(0, 999999);
_root.soundno0="yes";



// snd1 = new Sound();
This action creates a new Sound object called as 'snd1'

// snd1.attachSound("loop1");
This action attaches the sound specified in 'loop1' (identifier) parameter to the specified Sound object i.e. snd1

// snd1.start(0, 999999);
This action starts playing the attached sound from the beginning. '999999' specifies the number of times the sound should play consecutively.

// _root.soundno0="yes";
This action creates a variable named as 'soundno0' and sets its value as 'yes' in root of the Flash movie.


14. Select frame 3 and choose Insert > Keyframe

15. Choose Window > Actions

16. In the Actions panel type the following action

stop();


// stop
();
This action on frame 3 lets the Flash movie to stop at frame 3.


17. Select frame 3 on other two layers and choose Insert > Frame

18. Choose Control > Test Movie

You can hear the background sound playing but the volume slider is not still working.


19. Select slider movie clip on the stage and choose Edit > Edit in Place

20. Select the slider drag movie clip and choose Window > Properties

21. In the Properties panel type Instance name as 'sliderbutton'



22. Insert a new layer and name it as 'Actions'

23. Select frame 2 and choose Insert > Keyframe

24. Choose Window > Actions

25. In the Actions panel type the following actions.

level = int(sliderbutton._y);
_root.snd1.setVolume(_root.volume.level);

// level = int(sliderbutton._y);
This action determines the Y position of the sliderbutton and stores it in variable named as 'level'

// _root.snd1.setVolume(_root.volume.level);
This action sets the volume for Sound object snd1, according to 'level' variable.

26. Select frame 2 on all other layers and choose Insert > Frame.

27. Choose Control > Test Movie.

Now you can hear the sound as well as can adjust the volume with the help of volume slider.

The current playing sound will be the default sound. We are going to create 2 sound options including the default one. For that we need to create 2 buttons for 2 different sounds.

1. Go back into Scene 1

2. Insert a new layer above Slider layer and rename it as 'Track 1 Button'

3. Create an object as shown in the image and convert it into a Graphic named as 'button graphic'



4. Select the button graphic and choose Insert > Convert to Symbol to convert it into a Button. Name it as 'track1 button'.

5. Double click the track1 button to go inside it or choose Edit > Edit in Place

6. Insert a new layer over the existing layer and with the help of Text tool type a number as '01'

 

7. Choose Window > Library > track1 button

8.
Right click and select Duplicate to make same copy of track1 button. Rename the duplicated button as track2 button

9. Double click the track2 button in the Library to go inside it and make necessary changes. e.g.. Change the number from 01 to 02.

10. In Scene 1, place track 2 button on a new layer above Track 1 Button layer. Rename the newly added layer as 'Track 2 Button'.

11. Select track1 button on the stage and choose Window > Actions

12. In the Actions panel type the following actions


on (release) {
  stopAllSounds();
  _root.soundno1 = "yes";
  _root.soundno2 = "no";
  snd1.start(0, 999999);
}

// stopAllSounds();
This action stops all playing sounds in the Flash movie.

// _root.soundno1 = "yes";
This action creates a variable named as 'soundno1' and sets its value as 'yes' in root of the Flash movie.

// _root.soundno2 = "no";
This action creates a variable named as 'soundno2' and sets its value as 'no' in root of the Flash movie.

// snd1.start(0, 999999);
This action starts playing the attached sound from the beginning. '999999' specifies the number of times the sound should play consecutively.


13. Select track2 button on the stage.

14. In the Actions panel type the following actions

on (release) {
  stopAllSounds();
  _root.soundno2 = "yes";
  _root.soundno1 = "no";
  snd2 = new Sound();
  snd2.attachSound("loop2");
  snd2.start(0, 999999);
}

// stopAllSounds();
This action stops all playing sounds in the Flash movie.

// _root.soundno2 = "yes";
This action creates a variable named as 'soundno2' and sets its value as 'yes'.

// _root.soundno1 = "no";
This action creates a variable named as 'soundno1' and sets its value as 'no'.

// snd2 = new Sound();
This action creates a new Sound object called as 'snd2'

// snd2.attachSound("loop2");
This action attaches the sound specified in 'loop2' (identifier) parameter to the specified Sound object i.e. snd2

// snd2.start(0, 999999);
This action starts playing the attached sound from the beginning. '999999' specifies the number of times the sound should play consecutively.


15. Choose Control > Test Movie to see how the sound can be changed with the help of track1 and track2 buttons.

Now we want a button through which the sound can be stopped or played at any time.

1. Insert a new layer above Track 2 Button layer and rename it as 'On-Off Button'

2. Create a sound icon. Here we have imported (Choose File > Import) a speaker icon image (sound.png).

3. Place the icon below the track2 button on the stage.

4. Choose Insert > Convert to Symbol and convert the icon into a Graphic and name it as 'speaker'.


5. Select speaker graphic, choose Insert > Convert to Symbol to convert the graphic into a Button and name it as 'on-off button'



© Image Online  2001-2003