Log in

View Full Version : getURL from xml with mp3 player



punstc
08-27-2007, 03:38 AM
i've been working on this for over a week i have an mp3 player where i'm pulling in a link from an xml file that is also used to populate a song list and 2 other buttons one called lyrics and another for downloading. so for each song it will have a button for the song a button for the lyrics and a button to download.All these buttons are really movie clips so your aware they aren't normal buttons. the lyrics button is what i'm trying to add the link onto so it will go to another page where the lyrics will be posted . looking at another mp3 player i saw a code for an info button which the link for that button was pulled from the xml file. i tried implementing that code into my mp3 player but can't get to work properly. that mp3 layer only had one button and was already placed on the stage not put in by the xml for each instance. I'm not sure if this has anything to do with why it won't work. can anyone look and see if i have everything laid out correctly heres the code. when i click on the lyrics button right now it opens up in the broswer but shows me a file d directory of where my files are.

heres the code



stop();

title_txt.autoSize = "left";
timeDisplay_txt.autoSize = "left";
toolTip._visible = false;
var amountLoaded:Number;
var duration:Number;

playlist = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
if (success) {
_global.songname = [];
_global.songband = [];
_global.songfile = [];
_global.lyrics = [];
for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
_global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
_global.songband[i] = playlist.firstChild.childNodes[i].attributes.band;
_global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
_global.lyrics[i] = playlist.firstChild.childNodes[i].attributes.lyrics;
attachMovie("butTemp","but"+i,i+50);
eval("but"+i).id=i;
_root["but"+i]._x = 5;
_root["but"+i]._y = 40 + (i*15);
_root["but"+i].but_txt.text = songname[i];
if (i >= 25){
_root["but"+i]._x = 160
_root["but"+i]._y = -5 + (i*15);
}
attachMovie("lyrics","lyricbut"+i,i+81);
eval("lyricbut"+i).id=i;
_root["lyricbut"+i]._x = 390;
_root["lyricbut"+i]._y = 40 + (i*15);

attachMovie("download","downloadbut"+i,i+112);
eval("downloadbut"+i).id=i;
_root["downloadbut"+i]._x = 455;
_root["downloadbut"+i]._y = 40 + (i*15);

trace(_global.lyrics[i])


_root["but"+i].onRelease = function(){
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
_root.sound_mc.songStarter(songfile[this.id]);
}

_root["lyricbut"+i].onRelease = function(){
getURL(_global.lyrics[i].info, "_blank")

}

}
}
_root.createEmptyMovieClip("sound_mc", 1);
_global.song_nr = random(songfile.length);
_root.sound_mc.songStarter(songfile[song_nr]);
};

function timer(sound_obj) {
time = sound_obj.position/1000;
min = Math.floor(time/60);
min = (min<10) ? "0"+min : min;
sec = Math.floor(time%60);
sec = (sec<10) ? "0"+sec : sec;
timeDisplay_txt.text = min+":"+sec+"/"+totalDuration;
}
function duration (){
timed = _root.sound_mc.sound_obj.duration/1000;
mind = Math.floor(timed/60);
mind = (mind<10) ? "0"+mind : mind;
secd = Math.floor(timed%60);
secd = (secd<10) ? "0"+secd : secd;
totalDuration = mind+":"+secd;
}
MovieClip.prototype.songStarter = function(file) {
if (this.sound_obj) {
this.sound_obj.stop();
delete this.sound_obj;
}
this.sound_obj = new Sound(this);
this.sound_obj.loadSound(file, true);
this.sound_obj.setVolume(0);
this.onEnterFrame = function() {
if (this.sound_obj.position>0) {
delete this.onEnterFrame;
timeInterval = setInterval(timer, 1000, this.sound_obj);
track = this.sound_obj.id3.songname;
artist = this.sound_obj.id3.artist;
this._parent.title_txt.text =artist+" - "+track;
} else {
this._parent.title_txt.text = "loading...";
}

};
this.sound_obj.onSoundComplete = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr]);
};
this._parent.volume1.dragger.onPress = function() {
startDrag(this, true, 0, this._y, this._parent.volBG._width, this._y);
_root.toolTip._visible = true;
setInterval(draggableTip,100);
function draggableTip(){
_root.toolTip._x = _root._xmouse;
}
this.onEnterFrame = function() {
var p = (this._x/this._parent.volBG._width)*100;
this._parent._parent.sound_mc.sound_obj.setVolume(p);

};
};
this._parent.volume1.dragger.onRelease = function() {
delete this.onEnterFrame;
stopDrag();

};
this._parent.volume1.dragger.onReleaseOutside = function() {
_root.toolTip._visible = false;
stopDrag();

};
};

function soundStatus(){
var amountLoaded = _root.sound_mc.sound_obj.getBytesLoaded() / _root.sound_mc.sound_obj.getBytesTotal();
_root.loader.loadBar._width = amountLoaded * 260;
duration = _root.sound_mc.sound_obj.duration;
position = _root.sound_mc.sound_obj.position;
_root.playHead._x = position / duration * 272 + 5;
}

btn_play.onRelease = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
this._parent.sound_mc.songStarter(songfile[song_nr]);
};
btn_stop.onRelease = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
this._parent.sound_mc.sound_obj.stop();
};
btn_fw.onRelease = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
(song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
_root.sound_mc.songStarter(songfile[song_nr]);
};
btn_rev.onRelease = function() {
clearInterval(timeInterval);
_root.timeDisplay_txt.text = "00:00/00:00";
(song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
_root.sound_mc.songStarter(songfile[song_nr]);
};
playlist.load("playlist.xml");
setInterval(duration,100);
setInterval(soundStatus,100);


xml setup is like this



<?xml version="1.0" encoding="UTF-8"?>
<songs>

<song name ="Test Track 1" band ="Band1" file="test1.mp3" lyrics="http://www.theskooks.com" />
<song name ="Test Track 2" band ="Band2" file="test2.mp3" lyrics="http://www.theskooks.com" />
<song name ="Test Track 3" band ="Band3" file="test3.mp3" lyrics="http://www.theskooks.com" />
<song name ="Test Track 4" band ="Band4" file="test4.mp3" lyrics="http://www.theskooks.com" />

</songs>



thanks for looking and the help i've been going crazy over this.

Medyman
08-27-2007, 04:24 AM
Could you please upload your source file somewhere so I can do some testing. It's hard to figure out what exactly is the problem without running some traces in XML instances.

punstc
08-27-2007, 04:34 AM
sure thing here's a link to a zip of my entire project.

www.manifolddesigns.com/mp3.zip


my trace shows that my 4 instances of the link are coming in. but when i click the button it opens the browser and shows me my folder directory.

thanks for taking a look really appreaciate it

Medyman
08-27-2007, 04:48 AM
I wasn't able to open your file. Are you using CS3?

If so, please save it as Flash 8 so that I can open it.

punstc
08-27-2007, 01:49 PM
alright its saved as flash 8 now. its the same link as before

Medyman
08-27-2007, 03:45 PM
Alright...I think I figured it out.

Your issue is definitely with the onRelease function of the lyrics button ("lyricbut").

So, let's look at the syntax that you had:


_root["lyricbut"+i].onRelease = function(){
getURL(_global.lyrics[i].info, "_blank")

}

The first bit of advice I'll give is to NEVER use the _root syntax. Use this._parent instead. _root doesn't work in AS3.0 anyway and if you haven't yet, you'll soon start to switch to AS3.0 (it's really a lot easier and faster than AS2.0).

Secondly, you're overusing the _root and _global path calls. If you're working from the root timeline (as you are), it's not necessary to make those kinds of calls.

It will still work with them however, as long as you don't too complicated and start embeding swfs within swfs.

The last bit that could be an issue is the ".info" sytax. I've actually never seen this used with XML implentations in ActionScript and I couldn't find anything about it in a quick Google search. I think what you're looking for there is "nodeValue". If you do a trace for that call, it comes up as undefined:


trace(_global.lyrics[i].info)

So (fixing for the last thing), right now we have this:

_root["lyricbut"+i].onRelease = function(){
getURL(_global.lyrics[i], "_blank")

}


If you test it though, it won't work. Why? Because the "i" variable is undefined inside of the onRelease function. The "i" variable only exists in the onLoad function but once you make a function call inside the onLoad, you have to set up all new variables.

You could solve this in one of two ways:
1) Declare new variables inside the onRelease. This method is redundant though.

or

2) Set up an aritrary property for each of the lyrics buttons which will refer to which node in the XML you are referring to. You've already done this by this code line:


eval("lyricbut"+i).id=i;



So.....

Now we have:

_root["lyricbut"+i].onRelease = function(){
getURL(_global.lyrics[this.id], "_blank")

}


And THAT should work....

punstc
08-27-2007, 10:37 PM
Wow man thanks so much been having so much trouble with this. I actually never saw .info for xml either but i saw it used in another mp3 player that did a similar function. any ways thanks a bunch works like a charm!