Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

SPONSORED BY

The Very Best Algebra Notes


The Very Best Algebra Notes for the Very Best Flash Games

 

FLASH ACTIONSCRIPT MUSIC MACHINE CODE LESSON

In this lesson, students learn how to code a music machine or juke box. The AS3 API object, methods and properties used in the lesson include addEventListener, function, load, MouseEvent, Sound, SoundChannel, SoundMixer, SoundMixer.stopall, Timer, TimerEvent.TIMER_COM
PLETE, Timer.start, and URLRequest.

In the program, background sounds of the sea start playing automatically. When the Nobody Knows button is clicked, the famous song, Nobody Knows, starts to play. When the Siren button is activated, sirens blare out. When the stop button is clicked the song and siren stop playing. If the music buttons are pressed repeatedly without first stopping the sounds, multiple songs and sirens will play at once. Clicking the siren repeatedly will create multiple sirens. Ideal for emulating multiple emergency vehicles.

To schedule an online Flash lesson, contact
mark.c.stansberry@gmail.com
, Text: (707)235-4095

MUSIC BOX CODE LISTING

You will need to replace the MP3 sound files with your own MP3 files for the code to work. You
will also have to add three buttons to the stage (with AS3 or graphically). The three buttons must be named
bluesongs, redsongs and Labelstop

To schedule an online tutoring session

email: mark.c.stansberry@gmail.com
Cell/Text: 707.235.4095


COPY AND PASTE TO DOWNLOAD CODE

var myRequest:URLRequest=new URLRequest("nobody_knows.mp3")
var nobody:Sound = new Sound();
nobody.load(myRequest);
//nobody.play();
var sirensong:Siren = new Siren();
var barksong:Bark = new Bark();
var sirenchannelone : SoundChannel = nobody.play();
var sirenchannel2 : SoundChannel = sirensong.play();
sirenchannelone.stop();
sirenchannel2.stop();

 

var Timer_One:Timer=new Timer(10,100);// 10 events at 100 milliseconds intervals

Timer_One.start();

Timer_One.addEventListener(TimerEvent.TIMER_COMPLETE, timer_fn);

function timer_fn(e_timer_fn:Event):void
{

trace ("Your Timer is Working")

};

bluesongs.addEventListener(MouseEvent.CLICK, bluesplay)
redsongs.addEventListener(MouseEvent.CLICK, redplay)
blue.addEventListener(MouseEvent.CLICK, violetplay)
Labelstop.addEventListener(MouseEvent.CLICK, violetplay)

function bluesplay (songevent:MouseEvent): void {
nobody.play();
//bluesongs.removeEventListener(MouseEvent.CLICK, bluesplay)
//sirenchannelone.stop();
}

function redplay (songevent:MouseEvent): void {
var sirenchannel2 : SoundChannel = sirensong.play();
//var sirenchannelone : SoundChannel = nobody.play();
}

function violetplay (songevent:MouseEvent): void {

//sirenchannelone.stop();
//sirenchannel2.stop();
//var sirenchannel2 : SoundChannel = sirensong.play();

SoundMixer.stopAll();

trace("atop");
}

http://www.3d-perspective-software-development.com/lesson-flash-as3-music-sound-code.html