<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Prevent autoplay in my music player' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Prevent autoplay in my music player' posted on the 'Flash development' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 18 May 2013 19:47:23 -0700</pubDate>
    <lastBuildDate>Sat, 18 May 2013 19:47:23 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Prevent autoplay in my music player</title>
      <link>http://www.programmersheaven.com/mb/flash/425574/425574/prevent-autoplay-in-my-music-player/</link>
      <description>I need a simple change for my script below. The music keeps on autoplay as soon as it loads. How do it stop it from autoplay?&lt;br /&gt;
&lt;br /&gt;
I tried stop(); but it doesn't work.&lt;br /&gt;
Pls help. Im a noob in this.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
import flash.filters.DropShadowFilter;


var infostruc:Array = [];
var xmlData:XML = new XML();
xmlData.ignoreWhite = true;



//////////////////////////////// VARIABLES START /////////////////////////////
xmlData.load('songs.xml');					//name of XML with songs
this.mvolume = 100;							//sound volume
this.equalizer_visible = true;				//show equalizer bars
this.shuffle_songs = false;					//enable/disable shuffle
var showTime = true;						//show actual position text
//////////////////////////////// VARIABLES END /////////////////////////////

mySound = new Sound();
this.player_mc.play_mc._visible=false;
this.current=-1;
this.pausetime = 0;
this.player_mc.song_name_txt.autoSize = true;
this.player_mc.song_artist_txt.autoSize = true;
this.player_mc.mute_mc.stop();


player_mc.bar1_mc._visible = player_mc.bar2_mc._visible = player_mc.bar3_mc._visible = equalizer_visible;
this.player_mc.song_time_txt._visible = showTime;

function newSound(link){
	this.mySound = new Sound();
	
	mySound.onSoundComplete = function(){
		loadNext();
	}
	mySound.setVolume(this.mvolume);
	mySound.loadSound(link,true);
	startBars();


}




function startBars(){
	player_mc.bar1_mc.gotoAndPlay(1);
	player_mc.bar2_mc.gotoAndPlay(10);
	player_mc.bar3_mc.gotoAndPlay(15);
			
}

function stopBars(){
	player_mc.bar1_mc.gotoAndStop(1);
	player_mc.bar2_mc.gotoAndStop(1);
	player_mc.bar3_mc.gotoAndStop(1);
}


this.player_mc.stop_mc.onPress = function(){
	mySound.stop();
	pausetime = 0;
	player_mc.play_mc._visible=true;
	player_mc.pause_mc._visible=false;
	stopBars();
}

this.player_mc.play_mc.onPress = function(){
	mySound.start(pausetime / 1000);
	player_mc.pause_mc._visible=true;
	player_mc.play_mc._visible=false;
	startBars();
}
this.player_mc.pause_mc.onPress = function(){
	pausetime = mySound.position;
	mySound.stop();
	player_mc.play_mc._visible=true;
	player_mc.pause_mc._visible=false;
	stopBars();
}

this.player_mc.next_mc.onPress = function(){
	loadNext();
	player_mc.pause_mc._visible=true;
	player_mc.play_mc._visible=false;
}

this.player_mc.prev_mc.onPress = function(){
	loadPrev();
	player_mc.pause_mc._visible=true;
	player_mc.play_mc._visible=false;
}

this.player_mc.mute_mc.onPress = function(){
	if(mySound.getVolume() != 0)
	{
		mySound.setVolume(0);
		player_mc.mute_mc.gotoAndStop(2);
	}else{
		mySound.setVolume(mvolume);
		player_mc.mute_mc.gotoAndStop(1);
	}
}

function updateName(id){
	if(infostruc[id].pic_url)
		loadUrl(infostruc[id].pic_url);
	else
		this.player_mc.picture_mc._visible = false;
	
	if(infostruc[id].name)
		this.player_mc.song_name_txt.text = infostruc[id].name;
	else
		this.player_mc.song_name_txt.text = infostruc[id].link;
		
	if(infostruc[id].artist)
		this.player_mc.song_artist_txt.text = infostruc[id].artist;
}

function getNextId(){
	if(infostruc.length==current+1)
		return 0;
	else
		return current+1;
}
function getPrevId(){
	if(0==current)
		return infostruc.length-1;
	else
		return current-1;
}

function loadNext(){
	current = getNextId();
	updateName(current);
	newSound(infostruc[current].link);
}

function loadPrev(){
	this.current = getPrevId();
	updateName(this.current);
	newSound(infostruc[current].link);
}

function f1()
{
 // percent loaded
 buffered=Math.floor((mySound.getBytesLoaded()/mySo
und.getBytesTotal())* 45);

 // display progress on the display
 //if(buffered&amp;lt;100) { totaltime=buffered; totaltime = totaltime+"%"; }

 // resize sound playing bar
 player_mc.position._xscale=(mySound.position/mySou
nd.duration)* 45;
 player_mc.duration._xscale=buffered;

 // display how many seconds played
 playedseconds=Math.floor(mySound.position/1000);
 playedtime=Math.floor(playedseconds/60) + ":" + playedseconds%60;
 
 timeseconds=Math.floor(mySound.duration/1000);
 time=Math.floor(timeseconds/60) + ":" + timeseconds%60;

 // if stopped remove sound bar
 //if(action=="stop"){ sndbar._xscale=0; }

 /*if(pause==1){
  pausepos=mySnd.position;
  mySnd.stop();
 }*/
 
 player_mc.song_time_txt.text = playedtime + ' / ' +time;
 //song_time_txt.text = playedtime ;

}



setInterval(f1,100);


var mclistener:Object = new Object();
mclistener.onLoadInit = function(target_mc:MovieClip){
		target_mc._width = 75;
		target_mc._height = 75;
		var myDropShadowFilter = new DropShadowFilter(0,65,0x333333,0.15,15,15,2,3,fals
e,false,false);
		target_mc.filters = [myDropShadowFilter];
}

mclistener.onLoadComplete = function(target_mc:MovieClip){
	target_mc._parent._parent.gotoAndPlay(2);
}

var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclistener);


MovieClip.prototype.loadUrl = function(url) {
	stopBars();
	image_mcl.loadClip(url,this.player_mc.picture_mc.i
mage_mc);	
}

player_mc.duration.onPress = function(){
	
	var pos = (player_mc._xmouse - player_mc.duration._x) / player_mc.duration._width;
	mySound.start( Math.floor(mySound.duration * pos) / 1000 );	
}

Array.prototype.shuffle=function(){
   for(i=0;i&amp;lt;this.length;i++){
      var tmp=this[i];
      var randomNum=random(this.length);
      this[i]=this[randomNum];
      this[randomNum]=tmp;
   }
}

xmlData.onLoad = function(success:Boolean):Void  {
	
	if (success) {
		for (var i:Number = -1; this.childNodes[0].childNodes[++i]; ) {
			var cNode:XMLNode = this.childNodes[0].childNodes[i].childNodes;
			var url:String = cNode[0].childNodes[0].nodeValue ? unescape(cNode[0].childNodes[0].nodeValue) : unknownSong;
			var pic:String = cNode[1].childNodes[0].nodeValue ? unescape(cNode[1].childNodes[0].nodeValue) : unknownSong;
			var nm:String = cNode[2].childNodes[0].nodeValue ? unescape(cNode[2].childNodes[0].nodeValue) : unknownSong;
			var ar:String = cNode[3].childNodes[0].nodeValue ? unescape(cNode[3].childNodes[0].nodeValue) : unknownSong;
			infostruc.push({link:url, name:nm, pic_url:pic,artist:ar});
		}
		this.song_name_txt.text = "";
		if(shuffle_songs==true)
			infostruc.shuffle();
			
		loadNext();
	} else {
		this.song_name_txt.text = "XML error";
		this.song_artist_txt.text = "";
	}
};


&lt;/pre&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/flash/425574/425574/prevent-autoplay-in-my-music-player/</guid>
      <pubDate>Fri, 04 Nov 2011 03:16:11 -0700</pubDate>
      <category>Flash development</category>
    </item>
  </channel>
</rss>