Sound in Actionscript3

Get Adobe Flash player

Click the cat to hear it meow, click the car to honk.

var honk:Honk=new Honk();
var meow:Sound=new Sound();
var req:URLRequest = new URLRequest("http://www.zebra0.com/sounds/CatMeow.mp3");
meow.load(req);
car.addEventListener(MouseEvent.CLICK, carClick);
car.buttonMode=true;
function carClick(event:MouseEvent):void {
  honk.play();
}

cat.addEventListener(MouseEvent.CLICK, catClick);
cat.buttonMode=true;
function catClick(event:MouseEvent):void  {
  meow.play();
}
Download movie

If we want to create a Cat class so that any cat can meow:

package  {
  import flash.display.MovieClip;
  import flash.net.*;
  import flash.events.*;
  import flash.external.*;
  import flash.media.*;
  public class Cat extends MovieClip {
  var meow:Sound=new Sound();
  public function Cat() {  // constructor code
    var req:URLRequest = new URLRequest("http://www.zebra0.com/resources/cat.mp3");
    meow.load(req);
    this.addEventListener(MouseEvent.CLICK, catClick);
    this.buttonMode=true;
  } //constructor
  function catClick(e:MouseEvent):void {
    meow.play();
  } //catClick
} //class
} //package
Download Cat.as

NEXT: Play a sound from the library (Demo)