Playing a Sound from a URL


Get Adobe Flash player

In order to play a sound, you either need to have the sound in the library, or play the sound from a URL.
In this example we will play a sound from a URL..

  1. Start a new flash movie.
  2. From the common libraries, buttons, drag a button to the stage and name the instance on the stage btnWin.
  3. Write the code to play the sound directly from the URL

Write the code as shown below:

btnWin.addEventListener(MouseEvent.CLICK, winner);

function winner(e:MouseEvent):void {
  var sound:Sound=new Sound();
  var req:URLRequest = new URLRequest("http://www.zebra0.com/flash/resources/win.mp3");
  sound.load(req);
  sound.play();
} //winner

Play a sound from the library

Download the finished movie

INDEX, Timer Class, Sound Class, URLRequest to play a sound, Start and Stop a Sound with a Channel, URLRequest to Open the Browser, Add New Child at Runtime, List to download classes
Next lesson: Document Class

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

URLRequest to play a sound