Chapter 5: Ride Runner Playlist Display And Control In Flash
Reading playlist from RR can be as complicated as you want to make it. Most of the work involves reading the label CUSTOMPL and parsing it for information. First and foremost, declare the label in your .skin file like so
Code:
L,-1000,-1000,1000,1000,,,,,,"CUSTOMPL"
big label for alot of data. The next step requires a little bit of understand of how CUSTOMPL is sorted. In short, CUSTOMPL holds your entire playlist.. which means only thru code will you know where you are within that list. Each item in that list is separated by chr(13) and is prefixed with "LST". With these bits of knowledge we can proceed with creating a loop to read each item.
Code:
onFrame (4) {
custompl= _root.CUSTOMPL;
playlist = _root.CUSTOMPL.split(chr(13));
}
onFrame (5) {
//tr is our current position in the playlist. because we're reading it for the first time the default position is 0.
tr = _root.TRACKNUMBER - 1;
}
The code above sets our defaults which we will use to test if CUSTOMPL has been modified. The playlist variable uses a split method to put each item of CUSTOM into an array.
Code:
onFrame (8){
if (oldtr <> _root.TRACKNUMBER) {
gototrack = "SETLIST;" + _root.TRACKNUMBER;
tr = _root.TRACKNUMBER - 1;
oldtr = _root.TRACKNUMBER;
}
t1 = substring(playlist[0 + tr],4,(length(playlist[0 + tr]) - 3));
t2 = substring(playlist[1 + tr],4,(length(playlist[1 + tr]) - 3));
t3 = substring(playlist[2 + tr],4,(length(playlist[2 + tr]) - 3));
t4 = substring(playlist[3 + tr],4,(length(playlist[3 + tr]) - 3));
t5 = substring(playlist[4 + tr],4,(length(playlist[4 + tr]) - 3));
t6 = substring(playlist[5 + tr],4,(length(playlist[5 + tr]) - 3));
t7 = substring(playlist[6 + tr],4,(length(playlist[6 + tr]) - 3));
tn1 = 1 + tr;
tn2 = 2 + tr;
tn3 = 3 + tr;
tn4 = 4 + tr;
tn5 = 5 + tr;
tn6 = 6 + tr;
tn7 = 7 + tr;
}
this frame does the bulk of our parsing. the first step simply checks to see if the current tracknumber matches our trackposition. If not, then we need to change the track position so that the currently playing track is always in the first playlist entry spot. t1 through t7 are dynamic text objects to display 7 songs within the playlist. Each is defined the same way.
t1 = substring(ArrayIndexHoldingListContent,4(to remove "LST"),(LengthOfListEntry - 3(3 being "LST")));
Easy to understand? Probably not! But practice will make it become easy. The next step is the tn... or TRACKNUMBER variable. These need to be defined for the list click command to work.
Code:
onFrame (10) {
if(custompl<>_root.CUSTOMPL){
gotoAndPlay(4);
}else{
gotoAndPlay(9);
}
}
This little bit here? This just allows us to check to see if CUSTOMPL need be read again. This reduces the overhead of parsing that content heavy variable for no reason. Thats how we read our create our playlist! But how do we control it? Well playlist movement is rather simple.. we just need to change our track position or "tr" variable. So an "UP" command in RR equals
Code:
on (press){
_root.list.tr = _root.list.tr-1;
if(_root.list.tr<1){
_root.list.tr = 1;
}
_root.list.gotoAndPlay(6);
}
and "DOWN" equals
Code:
on (press){
_root.list.tr = _root.list.tr+1;
if((int(_root.PLAYLISTCOUNT)-1)<_root.list.tr){
_root.list.tr = (int(_root.PLAYLISTCOUNT)-1);
}
_root.list.gotoAndPlay(6);
}
Thats easy enough. Lastly, how do we switch songs? We use our tn variable we've created~!
each of the t1-t7 dynamic text objects should have this press event
Code:
on (press){
gototrack = "SETLIST;" + tn1;
if (tn1 <> _root.TRACKNUMBER) {
fscommand(gototrack);
fscommand("PLAY");
}
//gotoandplay(6);
}
Again.. relatively easy peazy~! That pretty much sums up the basics of playlist handling in flash. Advanced users can parse things like album art path, seperate title+artist into two lines.. or practically anything else.
Bookmarks