{"id":882,"date":"2012-06-13T06:34:54","date_gmt":"2012-06-13T13:34:54","guid":{"rendered":"http:\/\/www.partnersinrhyme.com\/blog\/?p=882"},"modified":"2012-06-16T06:48:27","modified_gmt":"2012-06-16T13:48:27","slug":"flash-audio-creating-a-sound-onoff-button","status":"publish","type":"post","link":"https:\/\/www.partnersinrhyme.com\/blog\/flash-audio-creating-a-sound-onoff-button\/","title":{"rendered":"Flash Audio: Creating a Sound On\/Off Button"},"content":{"rendered":"<p>This tutorial will teach you how to create a Sound On \/ Off button for the music loop you have just added in the first flash tutorial.<br \/>This tutorial is built on top of the the tutorial &#8216;<a href=\"http:\/\/www.partnersinrhyme.com\/contact\/tutorials.php?sub=Flash&amp;cat=Adding%20Audio%20to%20Projects&amp;sno=61\">How To Import And Add Sound To A Movie<\/a>&#8216; that deals with the basics of importing sounds to Flash. This means that this tutorial assumes that you have a sound loop imported into the library of your movie. With the music loop in your library we can start building a button. <\/p>\n<p>Go to Insert -&gt; New Symbol or press Ctrl + F8 (Image 1).<\/p>\n<p><img hspace=\"5\" vspace=\"5\" alt=\"on off audio button in flash\" src=\"http:\/\/www.partnersinrhyme.com\/contact\/images\/flashonoff\/image_1.jpg\" \/><\/p>\n<p>Ok, now the dialog box titled &#8216;Create New Symbol&#8217; appears. Type in the name box &#8216;SoundOnOffButton&#8217; for type select &#8216;Button&#8217; and click &#8216;Ok&#8217;. Before clicking the Ok button, you button should look similar to image 2.<\/p>\n<p><img hspace=\"5\" vspace=\"5\" alt=\"sound on off button in flash project\" src=\"http:\/\/www.partnersinrhyme.com\/contact\/images\/flashonoff\/image_1.jpg\" \/><\/p>\n<p>The button appears in the library and you should be now in the editing mode of the button. Take a look at the image 3 so will know what I&#8217;m talking about. <\/p>\n<p><img hspace=\"5\" vspace=\"5\" alt=\"sound on off button in flash\" src=\"http:\/\/www.partnersinrhyme.com\/contact\/images\/flashonoff\/image_3.jpg\" \/><\/p>\n<p>Rename the layer to &#8216;Speaker Graphic&#8217;. As you can suggest, the layer&nbsp; will display a graphic with a simple speaker. I used the line tool to draw something like this on the image 4. It&#8217;s not fancy, I know, but you get the idea. <\/p>\n<p><img hspace=\"5\" vspace=\"5\" alt=\"sound on off button in flash audio project\" src=\"http:\/\/www.partnersinrhyme.com\/contact\/images\/flashonoff\/image_1.jpg\" \/><\/p>\n<p>With this button, you can go to the main timeline by clicking on the back button above the timeline of the button (Image 5). <\/p>\n<p><img hspace=\"5\" vspace=\"5\" alt=\"sound on off button in flash audio project\" src=\"http:\/\/www.partnersinrhyme.com\/contact\/images\/flashonoff\/image_5.jpg\" \/><\/p>\n<p>On the main timeline add an additional layer &#8216;Actions&#8217;. Now you should have two layers in the main timeline. The upper one renamed &#8216;Actions&#8217; and the layer below renamed to &#8216;Content&#8217;. Select the first frame of the layer &#8216;Content&#8217; and drag the SoundOnOffButton from the library somewhere on the stage. In my sample I placed it on the upper right corner of the Stage (Image 6). When placed on the stage, in the Properties panel, give it an instance name of &#8216;sound_btn&#8217;. To do this, keep the button selected on the stage, open the properties panel (Window -&gt; Properites) and type &#8216;sound_btn&#8217; in the left text box where it says &#8216;&lt;Instance Name&gt;&#8217;. See image 6.<\/p>\n<p><img hspace=\"5\" vspace=\"5\" alt=\"audio loops in flash on off button\" src=\"http:\/\/www.partnersinrhyme.com\/contact\/images\/flashonoff\/image_6.jpg\" \/><\/p>\n<p>The next step you should do is to add a linkage name to your imported sound loop. To do this, open up the library, right click the sound file in select &#8216;Linkage&hellip;&#8217; (Image 7). <\/p>\n<p><img hspace=\"5\" vspace=\"5\" alt=\"soud on off button in flash\" src=\"http:\/\/www.partnersinrhyme.com\/contact\/images\/flashonoff\/image_7.jpg\" \/><\/p>\n<p>The &#8216;Linkage Properties&#8217; dialog box appears. Check the option &#8216;Export for ActionScript&#8217; and in the &#8216;Identifier&#8217; text box, type in &#8216;myTrack&#8217;. Make sure the dialog box looks similar to image 8 and then click Ok. <\/p>\n<p><img hspace=\"5\" vspace=\"5\" alt=\"sound on off button in flash how to\" src=\"http:\/\/www.partnersinrhyme.com\/contact\/images\/flashonoff\/image_8.jpg\" \/><\/p>\n<p>Now select the first frame of the layer Actions and open up the Actions layer (press F9). Type in (or paste) the following lines of code code:<\/p>\n<p>var mySound:Sound = new Sound();<br \/>mySound.attachSound(&quot;myTrack&quot;);<br \/>mySound.start();<br \/>var soundStarted:Boolean = true;<br \/>sound_btn.onRelease = function() {<br \/>&nbsp;&nbsp;&nbsp; soundStarted = !soundStarted;<br \/>&nbsp;&nbsp;&nbsp; if (soundStarted) {<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this._alpha = 100;<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mySound.start();<br \/>&nbsp;&nbsp;&nbsp; } else {<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this._alpha = 30;<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mySound.stop();<br \/>&nbsp;&nbsp;&nbsp; }<br \/>};<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial will teach you how to create a Sound On \/ Off button for the music loop you have just added in the first flash tutorial.This tutorial is built on top of the the tutorial &#8216;How To Import And Add Sound To A Movie&#8216; that deals with the basics of importing sounds to Flash. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[27],"tags":[],"_links":{"self":[{"href":"https:\/\/www.partnersinrhyme.com\/blog\/wp-json\/wp\/v2\/posts\/882"}],"collection":[{"href":"https:\/\/www.partnersinrhyme.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.partnersinrhyme.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.partnersinrhyme.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.partnersinrhyme.com\/blog\/wp-json\/wp\/v2\/comments?post=882"}],"version-history":[{"count":3,"href":"https:\/\/www.partnersinrhyme.com\/blog\/wp-json\/wp\/v2\/posts\/882\/revisions"}],"predecessor-version":[{"id":906,"href":"https:\/\/www.partnersinrhyme.com\/blog\/wp-json\/wp\/v2\/posts\/882\/revisions\/906"}],"wp:attachment":[{"href":"https:\/\/www.partnersinrhyme.com\/blog\/wp-json\/wp\/v2\/media?parent=882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.partnersinrhyme.com\/blog\/wp-json\/wp\/v2\/categories?post=882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.partnersinrhyme.com\/blog\/wp-json\/wp\/v2\/tags?post=882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}