|
|
FrozenHaddock Tutorials: Control sounds with buttons In this tutorial, you will learn one of the methods of controlling sound with buttons. You'll learn how to stop, and play a sound. First create a basic button by drawing a rectangle, adding text in front of it and then grouping the two objects together (ctrl+g). Then press F8 to convert the grouped objects to a button and click ok. For more info on button creation visit here.
Click on your button to select it and press F9 or open your ‘Actions’ panel by clicking on it. Enter the following code:
This basically means when the button is pressed frame 2 will be played.
Now to bring your song to the stage.
Insert a new frame into the timeline (F5) wherever you like, the further along you put it the more song you will hear. If you test your animation now (crtl + enter) you should hear the song being played.
Insert a new keyframe (F6) into the frame after the frame you just used. Go back to frame 2 and break apart your button (crtl + b) (NOTE: this is only if you want to change the text on your button to ‘Stop’). Using the text tool highlight your text and change it to stop, or something along those lines. Group the button and text again (ctrl + g) and then convert it to a button again (F8). Whilst the button is still selected open your actions panel (F9) and enter the following code: on(press){ Note that for your animation the number at the end of gotoAndPlay will be the frame with your second play button on. That’s sound buttons in a nutshell.
Written by: Drajon05
|
|