1 / 7

Sound File

Sound File. Step 1 : Import Sound File. Import your sound in the library selecting File > Import > Import to library . In the library right click on your sound file and select properties. Select the ‘Export to Actionscript ’ box and give the Class name ‘ MySound ’ and click ok. Step 2.

daryl
Download Presentation

Sound File

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sound File

  2. Step 1 : Import Sound File • Import your sound in the library selecting File > Import > Import to library. • In the library right click on your sound file and select properties. • Select the ‘Export to Actionscript’ box and give the Class name ‘MySound’ and click ok.

  3. Step 2 Select Insert > New Symbol and choose movie clip for the type and click ok. Frame 1 Frame 2 Background

  4. Now the code – you just need to copy and paste this to the main timeline //This stops the toggle buttons from playing the second frame. toggle_btn.stop(); //Variable to detect whether the number of times the toggle button has been clicked. varclickOnce:uint=0; //Creates a new instance of the imported sound. varmyLionSound:Sound= new LionSound(); //Create a new instance of the SoundChannel varaChannel:SoundChannel = new SoundChannel(); //This adds the mouse click event to the toggle button. toggle_btn.addEventListener(MouseEvent.CLICK, togglePlay); //If the toggle button has been clicked once then the sound plays //with an image of a stop symbol. If the toggle button is clicked //again then sound stops and the play symbol is displayed. function togglePlay(event:MouseEvent):void { clickOnce++; if (clickOnce==1) { aChannel=myLionSound.play(); toggle_btn.gotoAndStop(2); } if (clickOnce==2) { SoundMixer.stopAll(); toggle_btn.gotoAndStop(1); clickOnce=0; } } Sound – should be the called the same as the sound file in your library

  5. Extra Code • When the sound has finished playing you can also return back to the play symbol with the following. • The code uses the sound complete event to detect when the sound file has finished playing: aChannel.addEventListener(Event.SOUND_COMPLETE, soundCompleted); function soundCompleted(event:Event):void { toggle_btn.gotoAndStop(1); }

  6. Controlling Sound • To stop sound playing: SoundMixer.stopAll();

  7. Controlling Multiple sounds //This stops the toggle buttons from playing the second frame. main_menu.mainmenunar.stop(); //Variable to detect whether the number of times the toggle button has been clicked. varclickOnce:uint=0; //Creates a new instance of the imported sound. varmainmenunarVar:Sound= new mainmenunarsnd(); varambience:Sound= new cityamb(); //Create a new instance of the SoundChannel varaChannel:SoundChannel = new SoundChannel(); var aChannel2:SoundChannel = new SoundChannel(); //Play ambience sound aChannel2 = ambience.play(); //This adds the mouse click event to the toggle button. main_menu.mainmenunar.addEventListener(MouseEvent.CLICK, togglePlay); //If the toggle button has been clicked once then the sound plays //with an image of a stop symbol. If the toggle button is clicked //again then sound stops and the play symbol is displayed. function togglePlay(event:MouseEvent):void { clickOnce++; if (clickOnce==1){ //SoundMixer.stopAll(); aChannel2.stop(); aChannel=mainmenunarVar.play(); main_menu.mainmenunar.gotoAndStop(2); } if (clickOnce==2) { SoundMixer.stopAll(); main_menu.mainmenunar.gotoAndStop(1); clickOnce=0 aChannel2 = ambience.play(); } }

More Related