Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating soundtracks with buttons? 1

Status
Not open for further replies.

TheOdditie

Technical User
Mar 11, 2003
24
US
Alright, I'm a little new to Flash. I have messed with it before, but that was about a year ago, and even then I didn't have the best of luck with buttons. My first question is:
What is the best way to create a flash soundtrack for a website? Like you go to a bands website and they have like 5 different songs you can listen to while you browse their page, well I would like to do something like that, and would like to know the best/easiest way to do it.
My second question is:
Alright, I have thought of one way of doing the above, to create a movie with several scenes in it and each scene gets its own track except for the first scene that has the controls. Well I have gotten the play button to work, the only button i have tried so far, but if you click the play button again, it will start playin the song again without stopping the first one, it will just keep adding the song on there. How would I make it so that it will only play 1 song at a time? Hope that made sense. Thanks in advance.

TheOdditie
 
Everything you ever wanted to know about sound but were afraid to ask!

Regards,

oldman3.gif
 
I recently had to do this.........using mx so the code will only work for that

1. i created a text file with the names of the songs
&Name0=Jukebox&music0=&
&Name1=Dire Straits&music1=Dire&
&Name2=Bare Naked Ladies=Bare&
//add all the songs here
&numitems=3& //change this to your total. Dire, Bare are the names I gave to the mp3's. mp3's in same folder as text file and flash file
using a text file allows you to change the music without editing flash

2. open flash and place a combobox on stage. give it an instance name (list say)
add this code to the frame

mySound = new Sound();
mySound.loadSound(" true);
mySound.start();//gives the music to play when the site loads

mydata = new loadvars();
mydata.onload = function() {
numItems = myData.NumItems;
for (i=0; i<numItems; i++) {
var Name = eval(&quot;myData.Name&quot;+i);
var DataRow= eval(&quot;myData.music&quot;+i);
var DataProvider = { Link:DataRow};
list.addItem(Name, DataProvider);
}

list.setChangeHandler(&quot;SelectItem&quot;);
}

function SelectItem(){
mysound.stop();
mysound = new Sound();
var song = list.getSelectedItem().data[&quot;Link&quot;];
mySound.loadSound(&quot; + song + &quot;.mp3&quot;, true);
mySound.start();
}
mydata.load(&quot;songs.txt&quot;); //text file with the names of the songs

Thats it...when a user selects a song from the combobox it will start to play...making another selection will stop the current song and start a new one.
 
alright, i tried going along with the first site, but i can't even get the sound to load. and the second way, i really don't want a combo box like that, i actually have some buttons made for the controls i want to use, just don't know how to get everything to work right.
 
odditie...good luck but if you want the user to be able to select a song then you will need 5 buttons..easy to do but will take up space

napalm that will work fine
 
no, not all the way right there bill. I know there is a way to do it with just having a Play, Stop, Prev, Next buttons. I see it all the time. Its just a matter of tryin to figure out flash well enough to know how to do it. Oh yea, if it helps im using Flash MX. All I can really do with flash is animate stuff, not assign actions. I'm lost when it comes to action scripts.
 
yes.. and i can show you how if you want..your first post said 5 songs so i assumed some user choice..if you just want one song to stop, next to start, and so on till the user finds the one they want to listen to while they surf, then can do. but i still say the user ought to be able to jump right away to the track they want with no messing and endless clicking of buttons....or have i misunderstood what you are trying to do ?
 
i guess i wasn't fully clear on that, sorry. Yea I just want a button that the user keeps clicking through until they reach one they like.

I have an idea on how to do it. So far this is what I have thought of. Have each song in its own scene, and when you hit play it will bump you to the first scene with a song in it, well i have gotten that far. Now for the part I can't figure out, when you hit the next button it will stop the song that is playing and will send you into the next song.

Like I said before, i don't know the best way to do this, so right now the song is an instance on a blank scene, when you click play it will go to the scene real quick then go back to the first scene with the controls. I know that placing the mp3 as an instance isn't the best way to do it, but I know no other way. I tried going by that first link and doing as it says, but I don't know exactly where to put all that script at.

Here is my website. I have my music buttons on there right now, and its just one song. Any suggestions?
 
no do it all with actionscript

forget scenes, instances etc


place the songs in an array on the main timeline

then use the button to loop through them
 
alright, well then you just completely lost me. I'm pretty new to all this flash stuff, and its hard for me to learn because i don't know where i can get some examples of how to do this from. Once I get something to look at like that, i will figure it out quite easy, then probably slap myself for not thinking of it.
 
if you point me to a place that will give me some examples on this, it would be greatly appreciated.
 
short explanation...ill place a more detailed one tomorrow if you still dont get it (getting the hang of it aint easy some times)

the code i gave above looped through a text file (that FOR stuff) and added the items it found to a combobox. just as easy to keep it an array..well it did but never mind

arrays have an index number..start with zero then go up.. you have a variable set to zero and add 1 to that variable on each buton click

so track0 is first element in the array
track1 second element and so on

plenty of tutorials on arrays around

start with
go to tutorials and look for arrays
 
ok thanks man, if i still have problems ill come back:)
 
Ok, its official, I don't like Flash. Can you just tell me how to do it so I can get it over with. I seriously do not get along with Flash, too many things to learn to do one simple thing. I'm definitely a Dreamweaver, Photoshop guy, not Flash.
 
Can you post a link to your present .fla, regarding this matter. Regards,

oldman3.gif
 
main timeline

var i = 0;

on the button (next)

on (release){
mysound.stop();
song = [&quot;track&quot; + _root.i] + &quot;.mp3&quot;;
mySound = new Sound();
mySound.loadSound(&quot; true);
mySound.start();
if (_root.i==4){_root.i=0;}else{_root.i=_root.i+1;}
}

all songs in same folder as swf and named tack0, track1, etc
 
Alright, is that supposed to be
if (_root.i==4)
?

2 equal signs? if so that cool, just wanting to make sure. Also, to make a prev button, just switch the + signs with - signs? And what would I put on the play button? just no + or - symbols, everything else the same? Sorry I have to ask so many questions, I usually can learn programs quick, but Flash isn't the same with me.

Thanks for all the help so far though.
 
the code is correct
all on one button
clicking the button will take you through the tracks one at a time. at the 5th track you do back to the first

==4 is correct syntax

5 tracks 0 to 4
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top