Groups | Blog | Home
all groups > flash actionscript > march 2006 >

flash actionscript : FlashVar > Load SWF or MP3


Mannix
3/22/2006 3:31:54 PM
You have to create a Sound object in your Flash file that loads your
sample_audio.mp3. Here's an example:

var mySound:Sound = new Sound();

// Set true to false if you don't want the sound to stream
mySound.loadSound("sample_audio.mp3",true);

playButton.onPress = function(){
mySound.start();
}

Things can a little more complicated if you want to make like a
preloader for the song or make a bar with the current position being
played. I suggest you look in the help files for Action Script 2.0 for
Sound object and read up on it.

Hope that helps,
Mannix
TCeko1
3/22/2006 9:36:44 PM
Hello All,
I'm a flash beginner and I've been working on something for a couple days,
with absolutely no luck. I'm sure there is a very simple solution, but I have
been unable to find it.

Here is what I'm trying to do:
1) I have an audio file, we'll call it sample_audio.swf or sample_audio.mp3
2) I have a flash movie with a play button on it.
3) When the flash movie is opened in a web page using object or embed, I would
like the sample_audio file to be loaded.
4) when someone clicks on the play button, I would like the sample_audio file
to play.

Any assistance would be greatly appreciated.
phonemymum
3/22/2006 11:27:08 PM
There are a few ways to acheive this. You can load you MP3 dynamically and
stream it over a web server, or to begin here is a version using AS and the
attachSound method:

sound = new Sound();
sound.attachSound("sample_audio.mp3");

this.mystart_btn.onRelease = function ()
{sound.start();
}
this.mystop_btn.onRelease = function ()
{sound.stop();
}

To make this work you need to import your file into the library and ensure the
mp3's linkage options are set accordingly.

There are a couple of other simple ways...but

Try this way first - see if is what you need.

Chris
TCeko1
3/23/2006 1:57:53 PM
Hello phonemymum,

First, let me thank you for your help with this issue.

Your solution is close to what I need. The only thing that is different is
that I need the mp3 file to reside outside of the final flash .swf be pulled in
via param (maybe with the FlashVars?).
Devendran
3/23/2006 2:24:21 PM
instead of attachSound use loadSound
dizcofly
3/23/2006 2:43:11 PM
This link has a nice working file, with volume slider too, and very
straightforward Actionscript:
http://www.kirupa.com/developer/mx/volume_slider.htm
The sound file is loaded from external source here and I have easily modified
this file for my use, to load many sound files sequentially.
Omkar S. Joshi
3/23/2006 2:58:01 PM
Hi TCeko1,

I will suggest that you also preload this external mp3 file and then take user
to the palyer frame. Otherwise player will load but soundfile will not start
playing immediately. It will take some time to load and then it will start
playing. User will be clueless on what is happening unless file starts playing.

Omkar S. Joshi
3/23/2006 2:59:42 PM
Hi TCeko1,

I will suggest that you also preload this external mp3 file as soone as your
movie loads completely and then take user to the sound palyer frame. Otherwise
player will be displayed but soundfile will not start playing immediately. It
will take some time to load and then it will start playing. User will be
clueless on what is happening unless file starts playing.

Hope suggestion helps....:beer;
TCeko1
3/23/2006 3:49:21 PM
Thank you all for your posts!

i guess i was not clear in what exactly how i needed the file called. I want
the mp3 file to be called from the html:

ie.
<param name="flashvars" value="soundFile=sample_audio.mp3">

Is this possible?

phonemymum
3/23/2006 6:26:53 PM
Hi

My solution was just to get the ball rolling...but you're in a different zone
altogether!

I don't think using flashVars is the solution your looking for though as in my
understanding it is limited to passing simple variables in flash, like text
then can be called immediately when the swf loads.

Dynamically loading the sound using onLoad event handler would seem more
appropriate - one of the solutions above?

This gentleman is a bit of a genius when it comes to sound?

www.kennybellew.com

Sorry couldn't help more!
AddThis Social Bookmark Button