# Autoplay on load

**URL:** <https://forum.kirupa.com/t/autoplay-on-load/180997>\
**Category:** Uncategorized\
**Created:** [March 5, 2006, 12:08pm UTC](https://forum.kirupa.com/t/autoplay-on-load/180997 "2006-03-05T12:08:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![buildrebuild](https://avatars.discourse-cdn.com/v4/letter/b/b782af/32.png) [@buildrebuild](https://forum.kirupa.com/u/buildrebuild)\
**Post date:** [March 5, 2006, 12:08pm UTC](https://forum.kirupa.com/t/autoplay-on-load/180997/1 "2006-03-05T12:08:14Z")

</div>

Hi,  
I’m having a problem.  
I have an MP3 player built so that when a link is clicked on an html page the player pops up in a new window(so people can continue looking through the site while listening to music).  
The problem is that the track is loaded in the new window by clicking a load button which loads the MP3 via XML. I want to do away with the button and have that first track load and play when the popup window opens.  
Any ideas?Here’s the code!!!  
Thanks in advance.  
BRb

//sound  
\_soundbuftime = 3;  
formatTime = function (millisecs) {  
var secs = Math.floor(millisecs/1000);  
var mins = Math.floor(secs/60);  
secs %= 60;  
if (secs\<10) {  
secs = “0”+secs;  
}  
if (mins\<10) {  
mins = “0”+mins;  
}  
return mins+":"+secs;  
};  
var snd = this.createEmptyMovieClip(“SoundController”, 1);  
snd.init = function() {  
snd.\_sound = new Sound(this);  
this.isPlaying = false;  
this.position = 0;  
loadingbar\_mc.\_xscale = 0;  
progressbar\_mc.\_xscale = 0;  
};  
snd.loadSound = function(url) {  
this.\_sound.loadSound(url, true);  
controls\_mc.play\_btn.onRelease();

this.updateTime();  
};  
snd.updateTime = function() {  
var time = formatTime(snd.position);  
if (time\_txt.text != time) {  
time\_txt.text = time;  
}  
};  
snd.\_sound.onSoundComplete = function() {  
controls\_mc.stop\_btn.onRelease();  
};  
snd.onEnterFrame = function() {  
if (this.isPlaying) {  
this.position = this.\_sound.position;  
}  
this.loaded = this.\_sound.getBytesLoaded()/this.\_sound.getBytesTotal();  
loadingbar\_mc.\_xscale = scrubber\_mc.\_xscale_this.loaded;  
progressbar\_mc.\_xscale = loadingbar\_mc.\_xscale_this.position/this.\_sound.duration;  
this.updateTime();  
};  
controls\_mc.play\_btn.onRelease = function() {  
textScroll\_mc.play();  
this.\_visible = false;  
if (!isPlaying) {  
snd.\_sound.start(snd.position/1000);  
snd.isPlaying = true;  
}  
};  
controls\_mc.pause\_btn.onRelease = function() {  
controls\_mc.play\_btn.\_visible = true;  
if (!snd.isPlaying) {  
return (0);  
}  
snd.position = snd.\_sound.position;  
snd.\_sound.stop();  
snd.isPlaying = false;

};  
controls\_mc.stop\_btn.onRelease = function() {  
controls\_mc.play\_btn.\_visible = true;  
snd.position = 0;  
snd.\_sound.stop();  
snd.isPlaying = false;  
};  
scrubber\_mc.onPress = function() {  
if (!snd.loaded) {  
return (0);  
}  
var pos = this.\_xmouse/100;  
snd.position = Math.min(snd.\_sound.duration, pos_snd.\_sound.duration/snd.loaded);  
if (snd.isPlaying) {  
snd.\_sound.start(snd.position/1000);  
}  
};  
SetSong = function (node) {  
snd.node = node;  
snd.loadSound(node.attributes.src);  
title\_txt.text = node.attributes.title;  
time\_txt.text = node.attributes.time;  
};  
snd.init();  
var soundtrack:Sound = new Sound();  
soundtrack.attachSound();  
volumeSlider\_mc.onMouseMove = function():Void {  
var currentVolume:Number = this.position\_mc.\_x/1;  
soundtrack.setVolume(currentVolume);  
};  
controls\_mc.play\_btn.enabled = false;  
//xml  
XMLNode.prototype.moveBefore = function(beforeNode) {  
if (this == beforeNode) {  
return (0);  
}  
beforeNode.parentNode.insertBefore(this.cloneNode(true), beforeNode);  
this.removeNode();  
};  
Clamp = function (min, n, max) {  
if (n\<min) {  
return min;  
}  
if (n\>max) {  
return max;  
}  
return n;  
};  
var song\_spacing = 40;  
var over\_node;  
GenerateSongListing = function (playlist\_xml, target\_mc) {  
target\_mc = target\_mc.createEmptyMovieClip(“list\_mc”, 1);  
var songs = playlist\_xml.firstChild.childNodes;  
for (var i = 0; i\<songs.length; i++) {  
var song\_mc = target\_mc.attachMovie(“song”, “song”+i, i);  
song\_mc.\_y = i_song\_spacing;  
song\_mc.node = songs\*;  
song\_mc.title\_txt.text = songs\*.attributes.title;  
song\_mc.time\_txt.text = songs\*.attributes.time;  
song\_mc.select\_btn.onRelease = function() {  
SetSong(this.\_parent.node);  
controls\_mc.play\_btn.enabled = true;  
this.enabled = false;  
this.\_visible = false;  
};  
}  
};  
var playlist\_xml = new XML();  
playlist\_xml.ignoreWhite = true;  
playlist\_xml.onLoad = function(success) {  
if (success) {  
GenerateSongListing(this, playlist\_mc);  
} else {  
trace(“Error loading XML file”);  
}  
// no success? trace error (wont be seen on web)  
};  
playlist\_xml.load(“mp3\_playlist2.xml”);
