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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MP3 Player - stop on open

Status
Not open for further replies.

Linda224

Programmer
Dec 6, 2006
80
US
Hello
I used this tutorial to create a mp3 player but it auto starts when opened.

How can I have it stopped when it opens and then the user has to press play to start it?

Thank you for any help
 
And then what?

Cause I found that and took it out and the player doesnt start on load but when you hit play it doesnt play either. It only played if you hit the next button.
 
Modify the mp3Player.as file to this...

Code:
var init:Boolean = true;

// Setup sound object
var s:Sound = new Sound();
s.onSoundComplete = playSong;
s.setVolume(75);

// Array of songs
var sa:Array = new Array();

// Currently playing song
var cps:Number = -1;

// Load the songs XML
var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = function()
{
	var nodes:Array = this.firstChild.childNodes;
	for(var i=0;i<nodes.length;i++)
	{
		sa.push(nodes[i].attributes.url);
	}
	playSong();
}

xml.load("songs.xml");

// Play the MP3 File
function playSong():Void
{
	if(cps == sa.length - 1)
	{
		cps = 0;
		s.loadSound(sa[cps], true);
		if(init){
			s.stop();
		}
	}
	else
	{
		s.loadSound(sa[++cps], true);
		if(init){
			s.stop();
		}
	}
}

Save the mp3Player.as.

In the mp3Player.fla, where I imagine you've added your controls, change the script on your play button to this...

Code:
on (release) {
	init = false;
	s.start(0,1);
}

Or to this depending on how you're coding your button...

Code:
play_btn.onRelease = function(){
	init = false;
	s.start(0,1);
}

Re-compile the .fla and it should then work fine!

Regards. FLASH HELP - OPENED FOR BUSINESS!
TO GET YOUR OWN FREE WEBSITE HOSTING
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top