...

View Full Version : Cookie String



TheMuffin
03-26-2007, 04:34 AM
I am using a function that successfully loads mp3s into a Flash player, eg:


appendPlaylist('1','example3.mp3','My Artist','My Title3','My URL','image.jpg');

I have modified the function to set and update a cookie each time the function is called - this works fine!

This however does not:


function load()
{
var myname ="playlist"
var tracks = getCookie(myname) // only one song in the cookie for testing
alert(tracks); // this displays: '1','example3.mp3','My Artist','My Title3','My URL','image.jpg'&
if (tracks != "") {
var tracklist = unescape(tracks)
tracklist = trimRecursive(tracklist) // this function strips the trailing '&' and any whitespace
var track = tracklist.split("&")
for(i = 0; i < track.length; i++){
alert(track[i]); // this displays: '1','example3.mp3','My Artist','My Title3','My URL','image.jpg'
appendPlaylist(track[i]);
}
}
}

It loads a "blank" track into the player :confused: If I substitute the following within the load() function itself, it works just fine:


appendPlaylist('1','example3.mp3','My Artist','My Title3','My URL','image.jpg');

To me its a mystery - could some kind soul please explain why?

Thanks!

TheMuffin

shyam
03-26-2007, 06:38 PM
function load()
{
var myname ="playlist"
var tracks = getCookie(myname) // only one song in the cookie for testing
alert(tracks); // this displays: '1','example3.mp3','My Artist','My Title3','My URL','image.jpg'&
if (tracks != "") {
var tracklist = unescape(tracks)
tracklist = trimRecursive(tracklist) // this function strips the trailing '&' and any whitespace
var track = tracklist.split("&")
for(i = 0; i < track.length; i++){
alert(track[i]); // this displays: '1','example3.mp3','My Artist','My Title3','My URL','image.jpg'
appendPlaylist(track[i]);
}
}
}


Are u sure ur calling it right ur calling appendPlaylist inside a for loop with a single argument...

TheMuffin
03-26-2007, 07:39 PM
No I am not sure - I am new to javascript and that is why I ask here for help ;)

To my mind, the variable track[i] contains a string with six arguments (as I see in the alert and show in my comment within the code). Are you saying that I must split track[i] into separate variables and then use those in the function?

TheMuffin

TheMuffin
03-26-2007, 11:17 PM
Ok this works... I cleaned up any quotes in the cookie first:


function load()
{
var myname ="playlist"
var tracks = getCookie(myname)
if (tracks != "") {
var tracklist = unescape(tracks)
tracklist = trimRecursive(tracklist)
var track = tracklist.split("&")
for(i = 0; i < track[i].length; i++){
var mylist = track[i].split(",")
appendPlaylist(mylist[0],mylist[1],mylist[2],mylist[3],mylist[4],mylist[5]);
}
}
}

Could somebody coach me on how to delay each iteration of the for loop? - the appendPlaylist function is asyncronous Ajax - I can get a return variable from the player for each call with appendPlaylist.

Thanks!

TheMuffin



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum