Adding Sound

What did you say? I can't hear you! Maybe you should add some MP3s to your Ming generated swf files!

At this time, MP3s are the only sound format available to us in Ming, and only fully upgraded WebTv units seem to support them. There are workarounds for using other sound files outside of your Ming swf file using action scripting and javascript, but that's another lesson!

Today, let's add a MP3 wolf sound effect to a moving moon shape (you can of course make better looking moons, this is basic for example).

A) Begin as always by starting your html document and opening your php code block


$moonGradient=new SWFGradient();

C) Next, let's create our moon shape using our circle code from previous lessons and the gradient fill we just created

$myMoon=new SWFShape();
$moonFill=$myMoon->addFill($moonGradient, SWFFILL_RADIAL_GRADIENT);
$ra = 50;
$a = $ra * 0.414213562; // = tan(22.5 deg)
$b = $ra * 0.707106781; // = sqrt(2)/2 = sin(45 deg)
$myMoon->movePenTo($x+$ra, $y);

D) Now, we define our movie and set it's attributes as always

$myMovie=new SWFMovie();

E) Next, we add our moon shape and position it, nothing new here


F) Now, let's add our wolf MP3 sound effect, notice that we use the standard php fopen command with a "r" attribute to read the file

$myMovie->streamMp3(fopen("DarkShadows.mp3", "r"));

G) Next, we animate our moon shape, using a loop though you can animate it step by step if loops make you uncomfortable

for($i=0; $i<400; $i++){

H) When adding MP3s to your Ming generated swf files, you should specify the number of frames needed, which you get by multiplying the number of seconds of your MP3 by the rate you set your movie to. This wolf MP3 is 10 seconds and the rate is set to 40 so our total frames equals 400


G) Finally, we save our movie, close our php code block, and add our html object tags as always

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=",0,0,0" ID=objects WIDTH=300 HEIGHT=200>
<PARAM NAME=movie VALUE="lesson14.swf">
<EMBED src="lesson14.swf" WIDTH=300 HEIGHT=200 TYPE="application/x-shockwave-flash" PLUGINSPAGE="">

What? I couldn't hear you!

Code summary for lesson 14