Groups | Blog | Home
all groups > flash actionscript > may 2005 >

flash actionscript : music in flash site


IcklePickle
5/17/2005 12:00:00 AM
Hi everyone,

i am creating a radio website and would like some advice on adding music. I
have created a volume button and added the music file to this movie clip in the
first frame. it works fine until i change pages (frames) which makes the first
instance of the music file continue and then begin another instance of the
music ontop. so two versions of the song are playing instead of the first
continuing as normal.

How can i have one song play throught the site (just once) but just continue
if i change pages. any ideas?
i thought i could just put the file on the last layer and have frames until
the end of the timeline. however i would then not be able to stop the music
unless i duplicate the flash file without music. this is why i put it in a
movie clip so maybe later i can stop it. does this make sense? if anyones got
any ideas, if you could please get back to me i would really appreciate it.

thanks

SMakinson
5/17/2005 12:00:00 AM
Take a look at the Sound class in the help panel under Actionscript Language
Reference. Using that you can either load the sound form an external file or
use attachSound from the library. This will give you better control of your
sounds.
kglad
5/17/2005 12:00:00 AM
use the flash Sound() object. it allows more precise control of your sound
than you can obtain by attaching a sound to a frame in the authoring
environment.

if the sound is already in your library, remove it from the frame attachment.
right click it in your library, click linkage, tick export for actionscript and
type a handy name in the indentifier field, say music1 and click ok.

then attached to a frame in your in movie you can use:

myS=new Sound();
myS.attachSound("music1");

and you can use all the properties of the Sound() object on myS to start,
stop, pause, control volume, pan etc of your music. check the flash help file
for details.
IcklePickle
5/18/2005 12:00:00 AM
hi kglad

thanks for explanation on how to use the sound object. i knew it existed but i wasnt sure what to do with it. thanks again i will try it out tonight.

thanks
kglad
5/18/2005 12:00:00 AM
IcklePickle
5/24/2005 12:00:00 AM
Hi kglad

I have tried out what you said. and this is the code i have used. I realise
there are a lot of methods i can use but im not quite sure what to do with them
and theres not much help either. However its not even playing now. Im not quite
sure what im doing to be honest. I realise the first one creates a new sound
variable and the second line attaches the sound to the frame. I then though
that the sound would need to be loaded and then i would need to get the volume
to set it and the start playing the music.

MyS = newSound();
MyS.attachSound("music1");
MyS.loadSound("music1");
MyS.getVolume();
MyS.setVolume(100);
MyS.start("music1");

could you give me an idea what im doing wrong?
thanks

SMakinson
5/24/2005 12:00:00 AM
MyS = new Sound();
MyS.attachSound("music1");
MyS.start();

Make sure you have the sound in your library with its linkage set to "music1".
IcklePickle
5/25/2005 12:00:00 AM
thank you for your help.

I have done all that however my problem still persists. the music begins to
play at the beginning of the site and continues if i click on other pages
(frames) however if i click on the homepage again the music begins again over
the first version. I thought about adding code to tell it to stop and start
again but then this wouldnt sound right. I want it to continue throughout the
site.

Would creating the sound in a new swf file and loading it in the other file be
a solution? would it not still load from the beginning again everytime someone
clicks on the homepage?

If you have any ideas that would be great.

kglad
5/25/2005 12:00:00 AM
if you're returning to the frame where you instantiated your Sound(), you might
want to use a toggle to prevent that sound from being re-instantiated:

if(!prevDefined){
MyS = new Sound();
MyS.attachSound("music1");
MyS.start();
prevDefined=1;
}
Tom
12/20/2005 2:12:26 PM
Did you find the solution to this? I am having the exact same problem...

From http://www.developmentnow.com/g/69_2005_5_0_0_522382/music-in-flash-site.htm

Posted via DevelopmentNow.com Groups
AddThis Social Bookmark Button